मैंRecordNotFound और belongs_to
ActiveRecord :: RecordNotFound: नहीं आईडी के साथ आदेश के लिए आईडी = 3 के साथ ग्राहक मिल सका =
जब एक के लिए एक आदेश प्रपत्र प्रस्तुत करने के लिए कोशिश कर रहा मौजूदा ग्राहक
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 से लेकिन मैंने विधि को लॉग किया और इसे भी बुलाया नहीं जा रहा है! इससे कोई फर्क नहीं पड़ता कि इसका नाम क्या है!
इस अंत नहीं है, भले ही यह आईडी से एक ग्राहक पाता है एक और ग्राहक बनाने? – dubilla