Using non-Railsy route to prepopulate a form

Posted by user94154 on Stack Overflow See other posts from Stack Overflow or by user94154
Published on 2010-06-02T23:32:18Z Indexed on 2010/06/02 23:34 UTC
Read the original article Hit count: 130

Filed under:
|
|

I have many instances of a Rails model, Post. When viewing an individual post, I'd like to create a form to create a child of Post called Comment. I'd like to prepopulate this form with a hidden tag that contains the post_id which is the foreign key in Comment.

The Railsy way to do this is to create a fancy-ish route such as:

/comments/new/post/:post_id

However, this gunks up the routes file and doesn't leave much flexibility. Let's say I want to create a link somewhere else that prepopulates a different attribute of the form...then I'd have to add another route for this.

So I think I'm going to create urls like this on /posts/show/:id:

/comments/new?comment[post_id]=<%= @post.id %>

This way I can add any other attributes as I need. I know the plus side associated with this, now what are the downsides?

© Stack Overflow or respective owner

Related posts about routes

Related posts about urls