This would probably be simpler for me if Ruby was my first language, but anyway, here s my question:
利用铁路 3.1,我试图接触一些配备Devise的战备经理,每当用户迹象时,就创造新的《刑法》。 我把这一逻辑放在我的应用程序管理员身上。 问题在于,当我创立一条《宪章》时,我想给它一个用户。 我曾尝试使用“Devises”助手方法,目前是用户,但那是 t。
Most importantly, I want to know why I can t access my helper methods or methods defined in the ApplicationController from within the Warden::Manager block. But I also want to know how I can edit my code so I can use Devise s current_user method (and my current_cart method, shown below) within the block without errors like the one listed below being called.
我的守则如下:
class ApplicationController < ActionController::Base
helper :all
helper_method :current_user
protect_from_forgery
before_filter :fetch_categories
.
.
.
def current_cart
@current_cart ||= Cart.find_by_user_id(current_user.id)
end
Warden::Manager.after_authentication do |user, auth, opts|
Cart.create!(:user_id => current_user.id)
end
end
Here s the error:
NameError in Devise::SessionsController#create
undefined local variable or method `current_user for ApplicationController:Class