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
und开发者_Python百科efined method `devise_for' for main:Object
Help would be greatly appreciated
Thanks
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.
精彩评论