Forum: Ruby on Rails Association and validation

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.
Tiago Z.C (Guest)
on 2009-04-08 05:03
(Received via mailing list)
Hi
I'm having some issues with models that i don't know which is the best
way
of doing that.

I have Post model...

class Post < ActiveRecord::Base

  validates_presence_of :name, :title

  has_many :comments

end


and the Comment model.


class Comment < ActiveRecord::Base

  validates_presence_of(:post)

  belongs_to :post

end


If I open the console, and start write some lines:

c = Comment.new

p = post.new

c.post = p

c.save


I receive the true feedback but, what about the presence of name and
title
on post???


Thank you...


--
Tiago Zortéa de Conto
Mac User - MAC OS X Leopard
MSN: removed_email_address@domain.invalid
Tiago Z.C (Guest)
on 2009-04-08 05:48
(Received via mailing list)
i'm sorry, forget my question, i found the awnser.

class Comment < ActiveRecord::Base

  validates_presence_of(:post)

  belongs_to :post, :validate => true

end

:)

On Tue, Apr 7, 2009 at 10:03 PM, Tiago Z.C 
<removed_email_address@domain.invalid> wrote:

>   has_many :comments
>
>
>
>
> --
> Tiago Zortéa de Conto
> Mac User - MAC OS X Leopard
> MSN: removed_email_address@domain.invalid
>



--
Tiago Zortéa de Conto
Mac User - MAC OS X Leopard
MSN: removed_email_address@domain.invalid
This topic is locked and can not be replied to.