To do things RESTfully in Rails and you have a model relationship like:class Post < ActiveRecord::Base
has_many :comments
end
You can set up your routes like this:map.resources :post, :has_many => :comments
This will generate URLs like: /posts/2/comments [ GET (index), PUT (new), UPDATE (edit)]
/posts/2/comments/10 [ GET (show)]
Then to construct your form for creating or editing comments, you can do this with form_for: form_for [@post, @comment] do |f|
...
end
Then in your CommentsController::update action, you will automatically have params[:post_id] so that comments are associated with the correct post
By the way, if you need to create those restful URLs by hand using url_for, this is how you would specify the create one: { :controller => :comments,
:action => :create,
:post_id => @post.id }
Notice that the controller is 'comments', even though the URL created with start with /posts