Model validations failed..(as there are two model used)

Is the code working properly?

Saurabh P. wrote:

Have you commented the line

in club.rb
validates_associated :user

no i haven’t commented this line…

Saurabh P. wrote:

Is the code working properly?

hi if i don’t fill any field then error messages are displayed for both
the model but also one message “club nil” as i wrote
validates_associated :club, :message => ‘nil’ in users model…and if i
fill data only for user model and don’t fill for club model then
validation called for club with message “club nil” and user doesn’t
save… and when i fill information for club model and not for user
model then only users model’s validation are called without that “club
nil” message…

so now only remaining thing is to remove that message display “club
nil”…as its work perfectly now…but thing is to now have to remove that
“club nil” message…

Preksha, I guess, you should read this:
http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributesHopefully,
it will solve your problem.

Thanks,
Abhinav

अभिनव
http://twitter.com/abhinav

On Tue, Sep 15, 2009 at 2:32 PM, Preksha P. <

Preksha P. wrote:

Saurabh P. wrote:

Is the code working properly?

hi if i don’t fill any field then error messages are displayed for both
the model but also one message “club nil” as i wrote
validates_associated :club, :message => ‘nil’ in users model…and if i
fill data only for user model and don’t fill for club model then
validation called for club with message “club nil” and user doesn’t
save… and when i fill information for club model and not for user
model then only users model’s validation are called without that “club
nil” message…

so now only remaining thing is to remove that message display “club
nil”…as its work perfectly now…but thing is to now have to remove that
“club nil” message…

hey can u tell me if i write validates_associated :club in users model
then when i don’t fill information for club then message is displayed
“club nil” or “club is invalid” so how can i remove this message??

if i write validates_associated :club, :message => ‘nil’ then club nil
message is displayed on validation called…
and if i write validates_associated :club, :message => nil then club is
invalid message is displayed on validations called…

so what should i write??
Please help me…

Saurabh P. wrote:

what message you get, if you remove :message => nil after
validates_associate :club

if i remove :message => nil then i get the message “club is invalid”

what message you get, if you remove :message => nil after
validates_associate :club

Preksha P. wrote:

Saurabh P. wrote:

what message you get, if you remove :message => nil after
validates_associate :club

if i remove :message => nil then i get the message “club is invalid”

I’m not getting what exact message you want?

Saurabh P. wrote:

Preksha P. wrote:

Saurabh P. wrote:

what message you get, if you remove :message => nil after
validates_associate :club

if i remove :message => nil then i get the message “club is invalid”

I’m not getting what exact message you want?

now all the things are working properly but when i don’t fill
information for club in the form then “club is invalid” message is
displayed with error messages due to validates_associated :club line
which i don’t want…

try this out,

in user.rb

def after_validation
variable = self.errors.reject{ |err| %w{club }.include?(err.first) }
self.errors.clear
variable.each { |err| self.errors.add(*err) }
end

might work.

Please correct me if I’m wrong

method after_validation collects all the error messages of club model
and rejects the first error message, which is “club is invalid” and
collects the remaining messages into variable and adds them to the error
list.

Saurabh

Saurabh P. wrote:

try this out,

in user.rb

def after_validation
variable = self.errors.reject{ |err| %w{club }.include?(err.first) }
self.errors.clear
variable.each { |err| self.errors.add(*err) }
end

might work.

hi Saurabh,

it is now working properly…
thank u soooooooo much…
but can u please tell me exact meaning of this methos after_validation??

Saurabh P. wrote:

Please correct me if I’m wrong

method after_validation collects all the error messages of club model
and rejects the first error message, which is “club is invalid” and
collects the remaining messages into variable and adds them to the error
list.

Saurabh

hey hello!!
you are not wrong this code is working properly as u told…

Thanks Saurabh…