Newbie learning Rails. I'm currently on Chp9 here:
http://railstutorial.org/chapters/sign-in-sign-out#top
At the end of the tutorial, rails is erroring (see below). being new
to Rails and after having checked the tutorial... How do you resolve
this kind of error. It's saying current_user is not defined, and it is
supposed to be defined with/Sites/sample_app/app/helpers/
sessions_helper.rb
NameError in Pages#home
Showing /Users/iamme/Sites/sample_app/app/views/layouts/
_header.html.erb where line #6 raised:
undefined local variable or method `current_user' for #<#<Class:
0x103371258>:0x10336be70>
Extracted source (around line #6):
3: <nav class="round">
4: <ul>
5: <li><%= link_to "Home", root_path %></li>
6: <% if signed_in? %>
7: <li><%= link_to "Profile", current_user %></li>
8: <% end %>
9: <li><%= link_to "Help", help_path %></li>
Trace of template inclusion: app/views/layouts/application.html.erb
Rails.root: /Users/iamme/Sites/sample_app
Application Trace | Framework Trace | Full Trace
app/helpers/sessions_helper.rb:13:in `signed_in?'
app/views/layouts/_header.html.erb:6:in
`_app_views_layouts__header_html_erb___1701013666_2174344740_524030'
app/views/layouts/application.html.erb:10:in
`_app_views_layouts_application_html_erb__1439570095_2174436720_0'
---- END
sessions_helper.rb CODE:
module SessionsHelper
def sign_in(user)
cookies.permanent.signed[:remember_token] = [user.id, user.salt]
current_user = user
end
def current_user=(user)
@current_user = user
end
def signed_in?
!current_user.nil?
end
def sign_out
cookies.delete(:remember_token)
self.current_user = nil
end
private
def user_from_remember_token
User.authenticate_with_salt(*remember_token)
end
def remember_token
cookies.signed[:remember_token] || [nil, nil]
end
end
--- END
thanks
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment