设计 - 记得我不工作吗?本地主机问题? [英] Devise - remember me not working? LocalHost Issue?
问题描述
我正在将设计与我的 rails 3 应用程序一起使用.由于某种原因,使用记住我"登录无法正常工作.
I'm using devise with my rails 3 app. For some reason the sign in with Remember Me is not working.
这可能是因为在 localhost:3000 上测试吗?
Could this be due to testing on localhost:3000 ?
在 devise.rb 中,我有以下设置:
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"}}
有什么问题吗?
我的 session_controller.rb 中也有以下内容
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
推荐答案
发生这种情况是因为 remember_me 以on"形式出现在参数中,但与 Devise::TRUE_VALUES 相比,它们是 [true, 1, '1', 't', 'T', 'true', 'TRUE'].
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'].
让它发挥作用的最简单方法是确保您的 remember_me 成为这些值之一.复选框示例(注意值=1"):
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" />
另一种方法,如果您想让它使用on"值,您可以将on"添加到 Devise::TRUE_VALUES.所以在你的 config/initializers/devise.rb 中添加第一行:
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屋!