Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?