我明白了
ActiveRecord::RecordNotFound: Couldn’t find Client with ID=3 for Order with ID=
在尝试为现有客户提交订单时.这通过键入以下内容通过表单或控制台进行:
Order.new(:client_attributes => { :id => 3 })
payment_form.html.erb:
<%= semantic_form_for @order,:url => checkout_purchase_url(:secure => true) do |f| %> <%= f.inputs "Personal information" do %> <%= f.semantic_fields_for :client do |ff| %> <%= ff.input :first_name %> <%= ff.input :last_name %> <!-- looks like semantic_fields_for auto-inserts a hidden field for client ID --> <% end %> <% end %> <% end %>
Order.rb:
class Order < ActiveRecord::Base belongs_to :client accepts_nested_attributes_for :client,:reject_if => :check_client def check_client(client_attr) if _client = Client.find(client_attr['id']) self.client = _client return true else return false end end end