Hi,
I’m using nested models to create form in my view. It looks like this:
<% form_for :user, :url => {:action => “add_owner” }, :html => {
:method => :post } do |u| %>
<% u.fields_for :agency_owner_attributes do |ao| %>
<% end %>
Both models: User and AgencyOwner:
class User < ActiveRecord::Base
has_one :agency_owner
accepts_nested_attributes_for :agency_owner
validates_associated :agency_owner
- validation here -
end
class AgencyOwner < ActiveRecord::Base
belongs_to :user, :class_name => “User”, :foreign_key => “user_id”
- validation here -
end
Controller:
def add_owner
@user = User.new(params[:user])
@user.save
end
The problem:
The whole idea of nested models is working. I can create two objects
(user and agency_owner) at once. When I display error_messages_for
‘user’ I get validation errors for both models (User and AgencyOwner) -
it’s working very well. But “fieldWithErrors”
fields from User model, so It’s impossible for highlight all error
fields from nested model. Do you have any idea how to fix it?
thanks for help