我刚刚开始使用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回复后,我可以在注册后看到remember_user_token
设置Cookie:
是否勾选了“记住我”。任何人都知道为什么会这样,以及如何阻止它?
相比之下,在中签名只会在勾选框时设置该cookie,如预期的那样。
答案 0 :(得分:1)
我现在你正在使用for_for,但我使用form_tag ...这样的代码适用于我的项目:
.form
= form_tag new_user_session_path do
= email_field_tag 'user[email]', nil, :placeholder => "Ваш e-mail", :required => true
= password_field_tag 'user[password]', nil, :placeholder => "Ваш пароль", :required => true
.submit-area
= submit_tag "Вход", :class => "orange-button"
= check_box_tag 'user[remember_me]', true
.login-link
Запомнить меня
因此该部分可以正常工作:
= check_box_tag 'user[remember_me]', true