我对使用设计注册的错误消息有疑问。在我的自定义设计控制器中,我有 create 方法,我将在验证失败时返回资源。由于某种原因,resource.errors 在呈现注册页面时被清除。有没有人遇到过这个问题?我正在使用 dm-devise 2.1.0
如果有帮助,这是我的代码:
class UserDevise::RegistrationsController < Devise::RegistrationsController
def create
begin
build_resource
....
rescue DataMapper::SaveFailureError => e
resource = e.resource
clean_up_passwords(resource)
respond_with resource
end
end
end
编辑:这是所要求的 clean_up_passwords 的代码(它们由设计定义):
def clean_up_passwords(object)
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
end
def clean_up_passwords
self.password = self.password_confirmation = nil
end
EDIT2:这是注册页面的查看代码:
<div class="account-container">
<div class="content clearfix">
<%= simple_form_for resource, :html => {:class => 'form-vertical'}, :url => registration_path(resource_name) do |f| %>
<h1>Create Account</h1>
<div class="login-fields">
<p>Please provide the following info:</p>
<%= f.input :name, :placeholder => "Full Name", :input_html=>{:class => "login username-field"} %>
<%= f.input :email, :placeholder => "Email Address", :input_html=>{:class => "login username-field"} %>
<%= f.input :password, :placeholder => "Password", :input_html=>{:class => "login password-field"} %>
<%= f.input :password_confirmation, :placeholder => "Password Confirmation", :input_html=>{:class => "login password-field"} %>
</div>
<div class="login-actions">
<%= f.button :submit, "Sign Up", :class => 'button btn btn-warning btn-large' %>
</div>
<% end %>
</div>
</div>