设计 - 记得我不工作?本地问题? [英] Devise - remember me not working? LocalHost Issue?
问题描述
这可能是由于本地主机测试:3000?
在devise.rb中,我有以下设置:
config.remember_for = 2.weeks
在日志中,当我发布登录信息时,我看到:
在Thu May 12开始POST / / users / sign_in为127.0.0.1 20:53:04 -0700 2011
SessionsController处理#创建为HTML
参数:{signIn=>LOG IN,authenticity_token=>GR09TIq4uSbu6UWxDRhpfQeLWp7qtJTxkCFksLmFzdE =,utf8=>✓,user=> {remember_me=& ,password=>[FILTERED],email=>xxxx@xxxxxxx-inc.com}}
有什么问题吗?
我的session_controller.rb中还有以下内容
class SessionsController< Devise :: SessionsController
/ pre>
prepend_before_filter:require_no_authentication,:only => [:new,:create]
include Devise :: Controllers :: InternalHelpers
#GET / resource / sign_in
def new
clean_up_passwords(build_resource)
render_with_scope:new
end
#POST / resource / sign_in
def create
resource = warden.authenticate!(:scope => resource_name,:recall = "new)
#set_flash_message:notice,:signed_in
sign_in_and_redirect(resource_name,resource)
end
#GET / resource / sign_out
def destroy
#set_flash_message:notice,:signed_out if signed_in?(resource_name)
sign_out_and_redirect(resource_name)
end
protected
def after_sign_in_path_for(resource)
如果resource.is_a?(User)&& resource.banned?
sign_out资源
flash [:error] =此帐户已被暂停。
root_path
其他
超级
结束
结束
结束
任何想要登录和记住的想法都不行吗?谢谢
解决方案发生这种情况是因为remember_me作为on进入params,但与Devise :: TRUE_VALUES进行比较, true,1,'1','t','T','true','TRUE']。
最简单的方法是让它工作确保你的remember_me成为这个值之一。复选框示例(通知值=1):
< input type =checkboxname =user [remember_me]value =1checked =checked/>
另一种方法,如果你想让它使用on值,你可以添加on设计:: TRUE_VALUES。
所以在你的config / initializers / devise.rb中,只需添加第一行:Devise :: TRUE_VALUES< ;< [on]
I'm using devise with my rails 3 app. For some reason the sign in with Remember Me is not working.
Could this be due to testing on localhost:3000 ?
in devise.rb, I have the following set:
config.remember_for = 2.weeks
In the logs, when I post a signin I see:
Started POST "/users/sign_in" for 127.0.0.1 at Thu May 12 20:53:04 -0700 2011 Processing by SessionsController#create as HTML Parameters: {"signIn"=>"LOG IN", "authenticity_token"=>"GR09TIq4uSbu6UWxDRhpfQeLWp7qtJTxkCFksLmFzdE=", "utf8"=>"✓", "user"=>{"remember_me"=>"on", "password"=>"[FILTERED]", "email"=>"xxxx@xxxxxxx-inc.com"}}
Is there anything wrong there?
I also have the following in my sessions_controller.rb
class SessionsController < Devise::SessionsController prepend_before_filter :require_no_authentication, :only => [ :new, :create ] include Devise::Controllers::InternalHelpers # GET /resource/sign_in def new clean_up_passwords(build_resource) render_with_scope :new end # POST /resource/sign_in def create resource = warden.authenticate!(:scope => resource_name, :recall => "new") #set_flash_message :notice, :signed_in sign_in_and_redirect(resource_name, resource) end # GET /resource/sign_out def destroy #set_flash_message :notice, :signed_out if signed_in?(resource_name) sign_out_and_redirect(resource_name) end protected def after_sign_in_path_for(resource) if resource.is_a?(User) && resource.banned? sign_out resource flash[:error] = "This account has been suspended." root_path else super end end end
Any ideas why signing in and remembering is not working? Thanks
解决方案This happens because remember_me comes in params as "on", but is compared to Devise::TRUE_VALUES, which are [true, 1, '1', 't', 'T', 'true', 'TRUE'].
The easiest way is to make it work is to insure your remember_me comes as one of that values. Example of check-box(notice value="1"):
<input type="checkbox" name="user[remember_me]" value="1" checked="checked" />
Another way if you want to make it work with "on" value you can add "on" to Devise::TRUE_VALUES. So in your config/initializers/devise.rb just add as the first line:
Devise::TRUE_VALUES << ["on"]
这篇关于设计 - 记得我不工作?本地问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!