Forum: Ruby on Rails Validation Through Multiple Models from one Form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Phillip B. (Guest)
on 2007-06-21 23:04
Hey All,

I have a form that submits data to multiple models.

I have

class Man < ActiveRecord::Base
  has_many :notes
  has_many :contacts

        validates_associated :contacts, :notes
  validates_presence_of :first_name
  validates_presence_of :last_name

class Contact < ActiveRecord::Base
  belongs_to :man

        validates_presence_of :contact_info

class Note < ActiveRecord::Base
  belongs_to :man

        validates_presence_of :notes

However when I submit the form blank, it will only validate for the Man
model. Not the other two. If I fill in the form then the data gets
submitted to the DB tables just fine, it just will not validate more
than that base model.

What am I missing??

Blessed Be

Phillip
Matt H (Guest)
on 2007-06-23 11:19
(Received via mailing list)
On 6/21/07, Phillip B. <removed_email_address@domain.invalid> wrote:
>   has_many :contacts
> class Note < ActiveRecord::Base
>   belongs_to :man
>
>         validates_presence_of :notes
>
> However when I submit the form blank, it will only validate for the Man
> model. Not the other two. If I fill in the form then the data gets
> submitted to the DB tables just fine, it just will not validate more
> than that base model.



From: <
http://api.rubyonrails.org/classes/ActiveRecord/Va...
>

"NOTE: This validation will not fail if the association hasn'EURO~t been
assigned. If you want to ensure that the association is both present and
guaranteed to be valid, you also need to use
validates_presence_of<http://api.rubyonrails.org/classes/ActiveRecord/Va...
. "

What am I missing??
>
> Blessed Be
>
> Phillip
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
Matt H <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.