Tim Sutcliffe
Tim Sutcliffe

Reputation: 185

Accessing devise helper 'user_signed_in?'

I'm unable to use 'user_signed_in?' in my application controller, and wondered if anyone knew how to fix it.

It's works fine in my views, but in my application controller i get

NoMethodError in PostsController#index
undefined method `user_signed_in?' for ApplicationController:Class

A lot of people had this problem on rail 3.0.3, but I'm using rails 2.3.8. The suggested fix was to use devise_for :user in your routes.rb but that resulted in

Internal Server Error
undefined method `devise_for' for main:Object 

Help would be greatly appreciated

Thanks

Upvotes: 1

Views: 1336

Answers (1)

Michael Durrant
Michael Durrant

Reputation: 96544

I use devise with 2.38 How about having

==> application_controller.rb <==
protected
 def authorize
   unless User.find_by_id(session[:user_id])
    session[:original_uri] = request.request_uri
    flash[:notice] = "Please Log In!"
    redirect_to :controller => 'admin', :action => 'login'
   end
 end
end

then each controller, e.g. food_items:

 class FoodItemsController < ApplicationController
 before_filter :authorize, :except => [:index, :show] # For all methods except these...

 # GET /food_items

slightly different approach. Might help.

Upvotes: 1

Related Questions