Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Active Record Associations in Rails Using Associations in Your App Creating an Associated Record

caven xu
PLUS
caven xu
Courses Plus Student 13,400 Points

How about separately writing `new` `create` in comments_controller ?

I 'noticed that we can use different ways to create a comment.

  1. use the way in this video: @post.comments.new in posts/show, then call[@post, comment] in partial;

  2. use: form_for @post.comments.new do |f| in partial

another way is create a views/comments/new then write new method(@post = Post.find(params[:post_id]), @comment = @post.comments.new) in comments_controller, finally call @comment in view

I haven't seen the first way before. Is this shorthand method new to rails? Which one is more usual in production?