views:

121

answers:

1

Hi i have 2 models

class User < ActiveRecord::Base
  has_one :core, :as => :resource
  validates_presence_of :name
end

class Core < ActiveRecord::Base
  belongs_to :resource, :polymorphic => true
  validates_presence_of     :email 
end

For insert a new user i use a form like this:

<%= error_messages_for :user %>
<% form_for :user, :html => { :multipart => true, :id => "user_form", :class => "core_form" }, :url => "/users/create" do |user_form| -%>
<% user_form.fields_for :core_attributes, @user.core do |core_form| %>
   <%= core_form.text_field :name %>
   <%= user_form.text_field :email %>
<% end %>
  <% end %>

when i submit this form without insert the email and the name, rails show me only the errors for user. i want core errors too in the same list How can i do?

thanks

+1  A: 

I think you might want validates_associated(*attr_names) http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M002171

"Validates whether the associated object or objects are all valid themselves. Works with any kind of association."

heavysixer