Problem with undefined variable current_user

Hi everyone,

I'm working through the tutorial at the following link and

attempting to customise/adapt the lessons for my own slightly different application.

Link:

[      Ruby

on Rails Tutorial: Learn Rails by Example | Ruby on Rails 3 Tutorial book and screencasts | by Michael Hartl](Ruby on Rails Tutorial | Learn Enough to Be Dangerous)

I'm currently trying to work through chapter 10, but having some

problems with the variable ‘current_user’ not being properly defined in the ‘signed_in’ method. Everything looks fine to me, but as I am obviously missing something I’d appreciate it if someone with more experience at debugging could point me in the right direction.

I can sign in with my test users and the exception only occures when

attempting to edit a profile.

Controller and model are attached.

Cheers,

Jen.

Error:

NameError in UsersController#edit

undefined local variable or method `current_user' for #<UsersController:0x9ffad80>

Rails.root: /home/resource_portal/website

Application Trace > Framework Trace > Full Trace

app/helpers/sessions_helper.rb:17:in `signed_in?'
app/controllers/users_controller.rb:91:in `authenticate'
rake-0.8.7/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:436:in `_run__1056153724__process_action__372525482__callbacks'
rake-0.8.7/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
rake-0.8.7/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
rake-0.8.7/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in `block in instrument'
rake-0.8.7/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
rake-0.8.7/ruby/1.9.1/gems/activesupport-3.0.3/lib/active_support/notifications.rb:52:in `instrument'
rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
rake-0.8.7/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_controller/metal/rescue.rb:17:in `process_action'
...

users_controller.rb (2.08 KB)

sessions_helper.rb (1.04 KB)

The error message is pretty clear - You haven’t defined a current_user method in your helper.

Check out Listing 9.16 in that tutorial you posted. That’s where it describes the current_user method you need to add.

http://ruby.railstutorial.org/chapters/sign-in-sign-out#code:current_user_working

Are you including SessionsHelper in you ApplicationController ?

class ApplicationController < ActionController::Base   protect_from_forgery   include SessionsHelper end

Simon

Hi, Moved the authenticate method to the helper, after looking at the sample app code from github. This seems to have solved the problem.

Thanks, Jen.