Forum: Ruby on Rails Simple question on inserting child data

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7ed559ec7f9fc6a96ddc1690f06e7f80?d=identicon&s=25 Chris Olsen (chrisolsen)
on 2007-01-19 16:29
(Received via mailing list)
after doing a bunch of reading I have finally sat down to create a
simple app to dirve home a lor of the concepts to which have been read.
 So I figured a simple blog app is the best way to do it.  The bad
thing is that I am already hung up when creating replies to a blog

I can't figure out how to insert the post_id value into the reply
table.  When creating a reply the user is directed to a page via a url
simular to the following http://localhost:3000/main/reply/4, with the
value 4 being the post_id that is being replied to.

In the controller I have:

class MainController < ApplicationController

  def index
    #display a list of the posts
    @posts = Post.find(:all, :order => "id desc")

  def reply
    #display the post that is being replied to
    @post = Post.find(params[:id])
    @reply =

  def post_reply
    @reply = Reply.find(params[:id])
    redirect_to :index


Here if the form
<h2><%= @post.title %></h2>
    <%= @post.content%>

<% form_for :reply, :url => {:action => :post_reply} do |form| %>

    <label for="content">Reply:</label>
    <%= form.text_area :content, :rows => 8, :cols => 50 %>

    <%= submit_tag "Submit" %>
<% end %>

So within the post_reply method in the controller, how do I get that
post_id from the url, or do I have to create a hidden input tag
containing it?

Thanks for the help
This topic is locked and can not be replied to.