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| %>

<li><label>Name: </label><%= u.text_field :name %></li>
<li><label>Surname: </label><%= u.text_field :surname  %></li>

<% u.fields_for :agency_owner_attributes do |ao| %>
<li><label>Agency name: </label><%= ao.text_field :name  %></li>
<li><label>Address: </label><%= ao.text_field :address  %></li>
<% end %>

<% 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" <div> is shown only for
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
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to