Я получаю
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 %>
<% 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
пришла от здесь, но я зарегистрировал метод, и он даже не вызывается! Неважно, как его зовут!