验证后设置注册错误消息或重置

时间:2012-12-14 15:38:00

标签: ruby-on-rails devise

我使用设计注册时出现错误消息问题。在我的自定义设计控制器中,我有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代码(由Devise定义):

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>

0 个答案:

没有答案