在我的应用程序控制器中,我有
protect_from_forgery
layout :layout_by_resource
def layout_by_resource
if devise_controller? && resource_name == :user && action_name == 'new'
"signin"
else
"application"
end
end
因此,登录、注册、忘记密码等设计视图使用该布局。
出于某种原因,在注册和忘记密码页面上,如果我遇到错误,它会重定向到/users
(如果注册页面错误)并且/users/password
如果忘记密码页面错误。然而,在登录页面上,它只显示正常的错误。
在我的signin
布局内容中,我有:
<% flash.each do |key,msg| %>
<div class="message" id="<%= key %>">
<%= content_tag :div, msg %>
</div>
<% end %>
<&= yield %>
对于登录视图,我有:
<%= form_for(resource, :as => resource, :url => session_path(resource)) do |f| %>
<p><%= f.text_field :email, :placeholder => "Email" %></p>
<p><%= f.password_field :password, :placeholder => "Password" %></p>
<p><%= f.submit 'Sign in', :class => "button" %>
<p><%= f.check_box :remember_me %><%= f.label :remember_me, "Stay Signed In" %></p>
<% end %>
对于注册视图,我有:
<%= form_for(resource, :as => resource, :url => registration_path(resource)) do |f| %>
<p><%= f.text_field :email, :placeholder => "Email" %></p>
<p><%= f.password_field :password, :placeholder => "Password" %></p>
<p><%= f.submit 'Sign up', :class => "button" %>
<% end %>
对于忘记密码的视图,我有:
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<p><%= f.email_field :email, :placeholder => "Email" %></p>
<p><%= f.submit "Reset", :class => "button" %></p>
<% end %>
知道出了什么问题吗?
更新
这是我在设计路线中覆盖的内容:
devise_scope :user do
get "/account" => "devise/registrations#edit"
get "/signin" => "devise/sessions#new", :as => "signin"
get "/signout" => "devise/sessions#destroy", :as => "signout"
end