[英]Accessing devise helper 'user_signed_in?'
我無法使用“ user_signed_in?” 在我的應用程序控制器中,想知道是否有人知道如何修復它。
在我看來,它工作正常,但是在我的應用程序控制器中,我得到了
NoMethodError in PostsController#index
undefined method `user_signed_in?' for ApplicationController:Class
很多人在3.0.3上遇到了這個問題,但是我在使用2.3.8。 建議的解決方案是在您的route.rb中使用devise_for:user,但這導致
Internal Server Error
undefined method `devise_for' for main:Object
幫助將不勝感激
謝謝
我在2.38中使用devise
==> 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
略有不同的方法。 可能有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.