title: Ruby on rails relationship reference saving
body: <p>I'm just wondering what is the best practice in saving this kind of data</p>
  
  <p>Here's the relationship of the models</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :posts, dependent: :destroy
    has_many :comments, dependent: :destroy
  end
  
  class Comment &lt; ActiveRecord::Base
      belongs_to :post
      belongs_to :user
  end
  
  class Post &lt; ActiveRecord::Base
      belongs_to :user
      has_many   :reviews
  end
  </code></pre>
  
  <p>Currently I'm saving them in this kind of code</p>
  
  <pre><code>def create
      @post = Post.find(params[:post_id])
      @comment = current_user.reviews.build(comment_param)
      @comment.post_id = params[:post_id]
      if @comment.save
          flash[:success] = 'Successfully created a comment'
          @post
      else
          flash[:error] = 'Error'
          @post
      end
  end
  </code></pre>
  
  <p>Here's the form opening tag.</p>
  
  <pre><code>form_for([@post,@post.comment.build]) do |f|
      %p
         = f.label :title, class: 'control-label'
         = f.text_field :title, class: 'form-control'
      %p
         = f.label :message, class: 'control-label'
         = f.text_area :message, class: 'form-control'
  </code></pre>
  
  <p>How can i shortcut it so that i will not assign the post_id manually and let the rails parse it </p>