# How pass the params :id to next action?

**URL:** <https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635>\
**Category:** Rails\
**Created:** [January 10, 2008, 8:23pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635 "2008-01-10T20:23:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![myst\_tt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myst\_tt](https://www.ruby-forum.com/u/myst_tt)\
**Post date:** [January 10, 2008, 8:23pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635/1 "2008-01-10T20:23:46Z")

</div>

Hi, everybody:  
I made a view - works as creating a new comment for a specific  
article, a example URL is “[http://localhost:3000/comments/new/2](http://localhost:3000/comments/new/2)”:  
here, comments is the controller, new is the action, 2 is the id of  
the specific article, which needs to be passed to next action  
“create”, so that this comment will be attached and displayed under  
2nd article. However, I didnt figure out how I can pass the id to next  
action named “create” in this controller, seems like only the  
“comments” is the only parameter when I click the “create” button…  
what can I do?

# the new view as follow:

# New comment

\<%= error\_messages\_for :comment %\>

\<% form\_for(@comment) do |f| %\>

**Desc**  
 \<%= f.text\_area :desc %\>

\<%= f.submit "Create" %\>

\<% end %\> ==================================

Thanks dudes!  
Myst

---

<div class="post-metadata">

**Author:** ![myst\_tt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myst\_tt](https://www.ruby-forum.com/u/myst_tt)\
**Post date:** [January 10, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635/2 "2008-01-10T20:27:18Z")

</div>

Shortly I wanna deliver not only the “comments” but also the “id” as  
params to next action.

---

<div class="post-metadata">

**Author:** ![myst\_tt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myst\_tt](https://www.ruby-forum.com/u/myst_tt)\
**Post date:** [January 10, 2008, 9:07pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635/3 "2008-01-10T21:07:18Z")

</div>

myst\_tt wrote:

> Shortly I wanna deliver not only the “comments” but also the “id” as  
> params to next action.

Pass the id to the URL that the form posts to.

\<% form\_for @comment, :url =\> {:id =\> @comment} do |f| %\>

---

<div class="post-metadata">

**Author:** ![myst\_tt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myst\_tt](https://www.ruby-forum.com/u/myst_tt)\
**Post date:** [January 10, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635/4 "2008-01-10T21:54:56Z")

</div>

good idea, RESTful… now I got to figure out how to do the nested  
URL in route.rb, but anyway, thanks for your comments!

Br,  
Myst

---

<div class="post-metadata">

**Author:** ![myst\_tt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myst\_tt](https://www.ruby-forum.com/u/myst_tt)\
**Post date:** [January 10, 2008, 9:41pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635/5 "2008-01-10T21:41:57Z")

</div>

Why not change the URL completely? Have it as /posts/2/comments/new?  
That  
way form\_for(@comment) _should_ generate the proper URL for it.

On Jan 11, 2008 6:37 AM, Jeremy Weiskotten  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![myst\_tt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myst\_tt](https://www.ruby-forum.com/u/myst_tt)\
**Post date:** [January 10, 2008, 10:22pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635/6 "2008-01-10T22:22:00Z")

</div>

Really big hand!

---

<div class="post-metadata">

**Author:** ![myst\_tt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@myst\_tt](https://www.ruby-forum.com/u/myst_tt)\
**Post date:** [January 10, 2008, 9:57pm UTC](https://www.ruby-forum.com/t/how-pass-the-params-id-to-next-action/125635/7 "2008-01-10T21:57:16Z")

</div>

map.resources :posts, :has\_many =\> :comments

or if you’re not using Rails 2.0

map.resources :posts do |post|  
post.resources :comments  
end

On Jan 11, 2008 7:24 AM, myst\_tt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > way form\_for(@comment) _should_ generate the proper URL for it.

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.
