我得到RecordNotFound與accepts_nested_attributes_for和belongs_to的
的ActiveRecord :: RecordNotFound:找不到客戶端與ID = 3與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
的reject_if
靈光乍現從here,但我登錄的方法,它甚至不被稱爲!不管它的名字是什麼!
這難道不是最終創造另一個客戶端,即使它通過ID找到一個客戶端? – dubilla 2014-07-02 22:46:49