Ruby on rails rails中的嵌套表单参数和简单表单
我试图让一个嵌套表单在一个表单中创建用户与其地址之间的关联 我看到的问题是,每当验证失败时,内部地址字段表单都不会重新填充,也不会显示验证错误 以下是表格:Ruby on rails rails中的嵌套表单参数和简单表单,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我试图让一个嵌套表单在一个表单中创建用户与其地址之间的关联 我看到的问题是,每当验证失败时,内部地址字段表单都不会重新填充,也不会显示验证错误 以下是表格: <%= simple_form_for(@user, :url => register_and_checkout_path, :html => {:class => "form-horizontal clearfix"}) do |f| %> <p>New Member & Gues
<%= simple_form_for(@user, :url => register_and_checkout_path, :html => {:class => "form-horizontal clearfix"}) do |f| %>
<p>New Member & Guest</p>
<small>Mandatory fields marked*</small>
<%= f.error_notification %>
<%= f.input :is_checkout, :as => :hidden, :input_html => { :value => true } %>
<%= f.input :first_name, :input_html => {:class => "input-xlarge"} %>
<%= f.input :last_name, :input_html => {:class => "input-xlarge"} %>
<%= f.input :email, :input_html => {:class => "input-xlarge", :placeholder => "you@youremail.com"} %>
<%= simple_fields_for (:address) do |a| %>
<%= a.input :phone1, :label => "Contact number", :input_html => {:class => "input-xlarge"} %>
<p class="uppercase">Your Address</p>
<%= a.input :address_1, :label => "Street Address", :input_html => {:class => "input-xlarge"} %>
<%= a.input :address_2, :label => false, :input_html => {:class => "input-xlarge"} %>
<%= a.input :address_3, :label => false, :input_html => {:class => "input-xlarge"} %>
<%= a.input :suburb, :input_html => {:class => "input-xlarge"} %>
<%= a.input :state, :input_html => {:class => "input-xlarge"} %>
<%= a.input :postcode, :label => "Postcode/zipcode", :input_html => {:class => "input-xlarge"} %>
<%= a.input :country, :priority => [ "Australia", "New Zealand", "Unites States", "United Kingdom" ] %>
<% end %>
<p>Become a valued member</p>
<%= f.input :password, :input_html => {:class => "input-xlarge"} %>
<%= content_tag(:button, :class => 'btn btn-large btn-success floatright') do %> <%= content_tag :i, '', :class => 'icon-white icon-shopping-cart' %> Register and Checkout <% end %>
<% end %>
</div>
最后是相关模型:
class Member::User < ActiveRecord::Base
authenticates_with_sorcery!
# attr_accessible :title, :body
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :address, :address_attributes, :first_name, :last_name, :order_attributes, :pending_order, :is_checkout
attr_accessor :is_checkout
# Orders and Order History
has_many :orders, :class_name => "Checkout::Order"
has_one :pending_order,
:class_name => "Checkout::Order",
:conditions => ['status = ?', 'P']
has_many :addresses, :class_name => "Member::Address"
has_one :primary_billing_address,
:class_name => "Member::Address",
:conditions => ['is_primary_billing = ?',true]
has_one :primary_shipping_address,
:class_name => "Member::Address",
:conditions => ['is_primary_shipping = ?',true]
has_one :address,
:class_name => "Member::Address",
:conditions => ['is_primary_billing = ?', true]
accepts_nested_attributes_for :address
accepts_nested_attributes_for :pending_order
validates_presence_of :email, :password, :first_name, :last_name
validates_confirmation_of :password
validates_uniqueness_of :email
end
class成员::用户“签出::订单”
有一个:待定订单,
:class_name=>“Checkout::Order”,
:条件=>['status=?','P']
有多个:地址,:class\u name=>“成员::地址”
有一个:主账单地址,
:class_name=>“成员::地址”,
:conditions=>['is_primary_billing=?',true]
有一个:主装运地址,
:class_name=>“成员::地址”,
:条件=>['is_primary_shipping=?',true]
有一个:地址,
:class_name=>“成员::地址”,
:conditions=>['is_primary_billing=?',true]
接受地址的\u嵌套\u属性\u
接受:挂起的\u订单的\u嵌套\u属性\u
验证是否存在:电子邮件、:密码、:名字、:姓氏
验证密码的确认
验证电子邮件的唯一性
结束
对于任何想找到这个问题答案的人来说,我发现了,这是一个非常简单的错误,花了很多时间试图找出答案,结果是表单中的这一行
<%= f.simple_fields_for :address do |a| %>
请注意,容器表单生成器现在引用了的简单字段
<%= f.simple_fields_for :address do |a| %>