首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ruby on Rails的未定义局部变量或方法‘`profile’

Ruby on Rails的未定义局部变量或方法‘`profile’
EN

Stack Overflow用户
提问于 2016-07-24 01:45:31
回答 2查看 503关注 0票数 0

在我的静态页面home.html.erb中,我有一个对StaticPagesController的引用。我相信我这样做是正确的,但仍然得到未定义的局部变量或方法‘`profile’。

StaticPagesController

代码语言:javascript
复制
class StaticPagesController < ApplicationController

    def profile
        redirect_to profile_path(current_user)
    end 
end

home.html.erb

代码语言:javascript
复制
<% if logged_in? %>
    <% profile %>
<% else %>
    <h1>Welcome to myProjects</h1>
    <%= link_to "Sign up!", signup_path, class: "btn btn-lg btn-primary" %>
<% end %>

EN

Stack Overflow用户

回答已采纳

发布于 2016-07-24 06:57:15

您需要将def profile作为帮助器方法,以便此方法可供查看。只需在您的def profile方法的下面添加以下行:

代码语言:javascript
复制
 helper_method :profile

您的最终类将如下所示:

代码语言:javascript
复制
 class StaticPagesController < ApplicationController

    def profile
      redirect_to profile_path(current_user)
    end 

    helper_method :profile
  end
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38544789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档