Simple question on inserting child data

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
posting.

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”)
end

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

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

end


Here if the form

<%= @post.title %>

<%= @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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs