← Back to Upcase

Part 1 current_user not defined


(Nicolo) #1

For some reason I’m getting undefined local variable or method current_user when trying to access it in the application.html.erb. Any idea why?

This is like minute 29 of part 1.

Here is what my application controller looks like:

    class ApplicationController < ActionController::Base
  protect_from_forgery

  def sign_in_as(email)
  	session[:current_email] = email
  end

  def current_user
  	OpenStruct.new(email: session[:current_email])
  end
end

(Geoff Petrie) #2

@Nicolo It may be because you haven’t declared current_user as a helper method.

try:

class ApplicationController < ActionController::Base
  protect_from_forgery

  def sign_in_as(email)
  	session[:current_email] = email
  end

  def current_user
  	OpenStruct.new(email: session[:current_email])
  end
  helper_method :current_user
end

(Nicolo) #3

That did it. Thanks!


(Geoff Petrie) #4

Awesome! :thumbsup: