在我的静态页面home.html.erb中,我有一个对StaticPagesController的引用。我相信我这样做是正确的,但仍然得到未定义的局部变量或方法‘`profile’。
StaticPagesController
class StaticPagesController < ApplicationController
def profile
redirect_to profile_path(current_user)
end
endhome.html.erb
<% if logged_in? %>
<% profile %>
<% else %>
<h1>Welcome to myProjects</h1>
<%= link_to "Sign up!", signup_path, class: "btn btn-lg btn-primary" %>
<% end %>
发布于 2016-07-24 06:57:15
您需要将def profile作为帮助器方法,以便此方法可供查看。只需在您的def profile方法的下面添加以下行:
helper_method :profile您的最终类将如下所示:
class StaticPagesController < ApplicationController
def profile
redirect_to profile_path(current_user)
end
helper_method :profile
endhttps://stackoverflow.com/questions/38544789
复制相似问题