设计sign_up忽略remember_me值
我刚刚开始使用 Devise。我有一个:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
并且我已将我的sign_up视图更改为:
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><%= f.email_field :email %></div>
<div><%= f.label :password %><%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><%= f.password_field :password_confirmation %></div>
<div><%= f.label :contact_me %><%= f.check_box :contact_me %></div>
<div><%= f.label :remember_me %><%= f.check_box :remember_me %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>
但是,检查POST响应,我可以在注册后看到在Cookie:
中设置的remember_user_token
,无论我是否勾选“记住我”或不勾选。有人知道这是为什么,以及如何阻止它吗?
相比之下,登录仅在勾选该框时才设置该 cookie,正如预期的那样。
I'm just getting started with Devise. I have a:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
and I've altered my sign_up view to:
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><%= f.email_field :email %></div>
<div><%= f.label :password %><%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><%= f.password_field :password_confirmation %></div>
<div><%= f.label :contact_me %><%= f.check_box :contact_me %></div>
<div><%= f.label :remember_me %><%= f.check_box :remember_me %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>
However, checking the POST response, I can see the remember_user_token
set in Cookie:
after sign-up whether I ticked "Remember me" or not. Anyone know why that is, and how to stop it?
By comparison, signing in only sets that cookie if the box is ticked, as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在您正在使用 for_for,但我使用 form_tag ...这样的代码适用于我的项目:
所以该部分可以正常工作:
I now that you are using for_for, but i use form_tag... Such code works on my project:
So that part will work fine: