开发者

Rails 3 helper_method

I have setup a helper method within the application controller ie.

class ApplicationController < ActionController::Base

  # Helpers
  helper_method :current_user

  # Private Methods
  private

  def current_开发者_C百科user
    @current_user ||= Tester.find(session[:user_id]) if session[:user_id]
  end

end

If I try to access to current_user variable within a view im getting an error

#code
Welcome <%=@current_user.first_name%>

#error
undefined method `first_name' for nil:NilClass

I know the session is good. Is this the correct was to access to current_user ?

Thanks for the help


It's a method, you're trying to access an instance variable, do it like this:

Welcome <%= current_user.first_name%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜