title: How to get the post id in rails?
body: <p>This is is how I have my models define for a simple blog</p>
  
  <pre><code>def User
    has_many :comments, :dependent =&gt; :destroy
    has_many :posts
  end
  
  def Post
    belongs_to :user
    has_many :comments
  end
  
  def Comment
    belongs_to :user
    belongs_to :post
  end
  </code></pre>
  
  <p>In my Post Controller I have this code so that I can create a comment in the view</p>
  
  <pre><code>  def show
      @post = Post.find(params[:id])
      @comment = Comment.new
      respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :xml =&gt; @post }
      end
    end
  </code></pre>
  
  <p>Then in my Comment#create I have this </p>
  
  <pre><code>  def create
      @comment = current_user.comments.create(params[:comment])
      if @comment.save
        redirect_to home_show_path
      else
        render 'new'
      end
    end
  </code></pre>
  
  <p>How should I make it so that my comment model can receive the post_id? I have done this in my Post show view as a fix but is there another way that is better?</p>
  
  <pre><code>&lt;%= f.hidden_field :post_id, :value =&gt; @post.id %&gt;
  </code></pre>