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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 April 2010 04:33, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 lotCan 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. On Apr 3, 8:33 am, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Apr 3, 8:26 am, Gautam <gdham...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > On Apr 3, 8:33 am, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 April 2010 17:44, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hey guys, thanks for the replies > > But those tutorials still dont tell you what to do in the contrller or > form view for my commentsThere are many tutorials out there that show how to make a basic blog with comments. Try google for rails tutorial blog. Colin> > 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 > > On Apr 3, 8:26 am, Gautam <gdham...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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. >> >> On Apr 3, 8:33 am, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > 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 > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Apr 2, 2010 at 8:33 PM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.