我无法使用'user_signed_in?'在我的应用程序控制器中,并想知道是否有人知道如何解决它。
它在我的视图中工作正常,但在我的应用程序控制器中我得到了
NoMethodError in PostsController#index
undefined method `user_signed_in?' for ApplicationController:Class
很多人在rails 3.0.3上遇到过这个问题,但我使用的是rails 2.3.8。建议的修复是 在routes.rb中使用devise_for:user,但结果是
Internal Server Error
undefined method `devise_for' for main:Object
非常感谢帮助
由于
答案 0 :(得分:1)
我用2.38设计
怎么样?==> 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
然后每个控制器,例如food_items:
class FoodItemsController < ApplicationController
before_filter :authorize, :except => [:index, :show] # For all methods except these...
# GET /food_items
略有不同的方法。可能有帮助。