Hi all,
Again I ask for your help with this issue after searching for a while
for a solution to no avail.
This simplified example illustrates the problem.
class User < ActiveRecord::Base
has_many :projects
accepts_nested_attributes_for :projects
end
class Project < ActiveRecord::Base
belongs_to :user
validates_presence_of :spec_name
before_validation :show
def show
puts "validating #{self.name}"
end
end
$ ./script/console
Loading development environment (Rails 2.3.18)
>> u1 = User.first
=> #<User id: 1, name: "Mary", created_at: "2013-05-07 19:51:56",
updated_at: "2013-05-07 19:51:56">
>> u1.projects_attributes = [{:spec_name=>'', :name=>'n1'}, {:spec_name=>'',
>> :name=>'n2'}]
=> [{:spec_name=>"", :name=>"n1"}, {:spec_name=>"", :name=>"n2"}]
>> u1.valid?
validating n1
validating n2
=> false
>> pp u1.errors
#<ActiveRecord::Errors:0x103454a80
@base=
#<User id: 1, name: "Mary", created_at: "2013-05-07 19:51:56",
updated_at: "2013-05-07 19:51:56">,
@errors=
{["projects.spec_name",
[#<ActiveRecord::Error:0x103452938
@attribute=:spec_name,
@base=
#<Project id: nil, user_id: 1, name: "n1", spec_name: "",
created_at: nil, updated_at: nil>,
@message=:blank,
@options={:default=>nil},
@type=:blank>]]=>nil}>
=> nil
As you can see, validation is done on both projects. However, when
looking at the errors it only shows one of them. I expected to see
both. The same thing occurs when updating instead of creating.
- Am I missing something?
- If not, can you suggest a workaround?
--
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
---
You received this message because you are subscribed to the Google Groups "SD
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.