为什么我得到未定义的方法“ cookies”? [英] Why I'm getting undefined method `cookies'?
问题描述
我正在尝试为我的rails后端应用程序设置具有single_access_token的Authlogic(我正在使用rails-api gem)。
I'm trying to setup Authlogic with single_access_token for my rails backend app (I'm using rails-api gem).
我正在关注以下示例: http:// blog。 centresource.com/2013/06/04/using-ember-auth-with-rails-3-and-authlogic/
I'm following this example: http://blog.centresource.com/2013/06/04/using-ember-auth-with-rails-3-and-authlogic/
到目前为止,我能够创建用户,但是当我尝试登录时,它在 user_session.save 上失败:
So far, I'm able to create users, but when I try to login it fails on user_session.save:
NoMethodError in Api::V1::UserSessionsController#create
undefined method `cookies' for #<Api::V1::UserSessionsController:0x00000004528cb8>
根据我在这里发现的类似问题,我必须将Authlogic配置为:
According to similar questions I've found here, I have to configure Authlogic as:
acts_as_authentic do |c|
c.login_field = :email
c.maintain_sessions = false
end
在我的用户模型上。但是,它一直在失败。我假设保存UserSession时,Authlogic尝试更新User上的魔术字段,但我不知道为什么仍要尝试使用cookie。
on my User model. However, it keeps failing. I'm assuming when UserSession is saved, Authlogic tries to update the magic fields on User, but I have no idea why is still trying to use cookies.
推荐答案
本教程假定使用常规的Rails应用程序,但是您正在使用rails-api。默认情况下,rails-api中的控制器不包含处理cookie的中间件。如果需要cookie,则需要添加该中间件:
The tutorial assumes a regular rails app, but you're using rails-api. By default controllers in rails-api don't include the middleware that handles cookies. If you need cookies then you need to add that middleware:
config.middleware.use ActionDispatch::Cookies
,然后在控制器中包含 ActionController :: Cookies
。在rails-api 自述文件
And then include ActionController::Cookies
in your controller. There's more info on what's included by default in the rails-api README
这篇关于为什么我得到未定义的方法“ cookies”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!