David_Zhu
(David Zhu)
April 3, 2010, 3:33am
1
I made a posts scaffold, and a comments scaffold
Now i want to link the two of them together by --
Post--
has_many :comments
and comments-
belongs_to :post
After that, I have no idea what to do in the controller or form for my
comments
What do i need to change in the comments controller and form so every
comment that gets created is assigned to a post?
Btw, i already have a post_id:integer column in my comments table
I REALLY NEED HELP!! thanks a lot
Can I suggest you work through the rails guides at
http://guides.rubyonrails.org/ . Start with Getting Started and work
through them.
Also an excellent tutorial is being developed at http://www.railstutorial.org/
Colin
Gautam1
(Gautam)
April 3, 2010, 12:26pm
3
I think you have already set up the has_many relationship. That is all
it takes.
Now you can display comments below every post by using a selection
operation matching the post_id colums in both tables.
something like...
find all where post_id = post_post
hope you got it.
David_Zhu
(David Zhu)
April 3, 2010, 4:44pm
4
hey guys, thanks for the replies
But those tutorials still dont tell you what to do in the contrller or
form view for my comments
I know i need to change something in the CREATE action of my comments
controller, so every comment that is created gets assigned to a post.
What exactly is it?
Thanks
hey guys, thanks for the replies
But those tutorials still dont tell you what to do in the contrller or
form view for my comments
There are many tutorials out there that show how to make a basic blog
with comments. Try google for rails tutorial blog.
Colin
Con
(Con)
April 4, 2010, 8:05am
6
I made a posts scaffold, and a comments scaffold
Now i want to link the two of them together by –
Post–
has_many :comments
and comments-
belongs_to :post
After that, I have no idea what to do in the controller or form for my
comments
What do i need to change in the comments controller and form so every
comment that gets created is assigned to a post?
Btw, i already have a post_id:integer column in my comments table
I REALLY NEED HELP!! thanks a lot
David, Ryan Bates has redone the classic Rails blog screencast which answers your
your question(s) quite nicely. Thus, you can find the screencast here and following
along:
http://media.rubyonrails.org/video/rails_blog_2.mov
Good luck,
-Conrad