在rails中获得验证错误时,注册表单的Devise + Clearing字段

时间:2014-06-17 13:55:20

标签: ruby-on-rails validation error-handling devise

我在我的rails应用中使用了Devise gem。现在我修改了注册表单,添加了许多字段,例如mobile_nofirst_namelast_name等等。现在,当我在提交表单email和{{1}时收到验证错误时}字段保持不变,但其他填充字段被清除。我希望所有填充的字段都应该是这样,因此用户不必再次输入所有数据。有没有解决方案..?请帮忙。提前谢谢。

应用/视图/设计/注册/ new.html.erb

username

应用/控制器/色器件/ registrations_controller.rb

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <div><%= f.label :name %>
  <%= f.select(:title, Title.all.collect { |t| [t.name, t.id] } ,:include_blank=> "Select") %>

  <%= f.text_field :first_name, :placeholder => "First Name" %>
  <%= f.text_field :last_name, :placeholder => "Last Name" %>
  <%= f.text_field :suffix , :placeholder => "Suffix"%>
  </div><br>

  <div><%= f.label :username %>
    <%= f.text_field :username %>
  </div><br>

  <div><%= f.label :email %>
    <%= f.email_field :email %>
  </div><br>

  <div><%= f.label :password %>
   <%=f.password_field :password %>
   <%= link_to("Generate Password", "#")  %>
  </div><br>

  <div><%= f.label :upload_Photo %>
    <%= f.file_field :avatar %>
  </div><br>

  <div><%= f.label :date_Of_Birth %>
   <%= f.text_field :dob, :as => :date_picker, :class => 'datepicker', :placeholder => "Click here to Select Date" %>
  </div><br>

  <div><%= f.label :role %>
    <%= select_tag(:role_ids, options_from_collection_for_select(Role.active, "id", "name"),:prompt=> "Select role") %>
  </div><br>

  <div><%= f.label :gender %>
  <%= select_tag :gender, options_for_select([['Male', 0], ['Female', 1]], :selected => :gender), :prompt => "Select gender" %></div><br>

  <div><%= f.label :address %>
  </div><br>

  <div><%= f.label :mobile_no %>
   <%= f.text_field :mobile_no  %>  
  </div><br>

  <div><%= f.label :landline_no %>
  <%= f.text_field :landline_no  %>  
  </div><br>

  <div><%= f.label :status %>
    <%= f.check_box :is_active %>
  </div><br>

  <%= f.submit %>

如果您需要,将提供任何所需信息

0 个答案:

没有答案