处理这个响应,我通过在有问题的控制器内部声明来包含在 application_helpers.rb 中找到的所有帮助程序helper "manager/application"
(如果'manager'是安装设计的可安装引擎的当前命名空间。如果你从这里调用它,只需使用'application'标准应用程序)。
会话控制器示例
require_dependency "manager/application_controller"
module Manager
class SessionsController < Devise::SessionsController
# Without this line I get errors like 'undefined method link_to'
helper "manager/application"
layout "manager/application"
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
sign_in_and_redirect(resource_name, resource)
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
return render :json => {:success => true}
end
def failure
return render :json => {:success => false, :errors => ["Login failed."]}
end
end
end