我用rails 3应用程序.由于某种原因,使用记住我登录不起作用.
这可能是由于本地主机测试:3000?
在devise.rb中,我有以下集合:
config.remember_for = 2.weeks
在日志中,当我发布登录后,我看到:
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"}}
那里有什么问题吗?
我在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
任何想要登录和记住的想法都不行吗?谢谢
解决方法
这是因为remember_me作为“on”进入params,但与Devise :: TRUE_VALUES进行比较,这是[true,1,’1′,’t’,’T’,’true’,’TRUE’].
最简单的方法是使其工作是确保您的remember_me作为其中一个值.复选框示例(notice value =“1”):
<input type="checkBox" name="user[remember_me]" value="1" checked="checked" />
另一种方式,如果你想使它的“on”值工作,你可以添加“开”到Devise :: TRUE_VALUES.
所以在你的config / initializers / devise.rb中添加为第一行:
Devise::TRUE_VALUES << ["on"]