# Restfull routes, link\_to, and additional paramters

**URL:** <https://www.ruby-forum.com/t/restfull-routes-link-to-and-additional-paramters/192666>\
**Category:** Rails\
**Created:** [August 3, 2010, 8:08pm UTC](https://www.ruby-forum.com/t/restfull-routes-link-to-and-additional-paramters/192666 "2010-08-03T20:08:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flamingsole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@flamingsole](https://www.ruby-forum.com/u/flamingsole)\
**Post date:** [August 3, 2010, 8:08pm UTC](https://www.ruby-forum.com/t/restfull-routes-link-to-and-additional-paramters/192666/1 "2010-08-03T20:08:48Z")

</div>

I am trying to do a link\_to with multiple to create an object.  
Everything works until ad the second parameter in. As soon as I add the  
second parameter, it forgets to add any information about the first one.

link\_to “create”, foos\_path(@foo, :bar\_id =\> @bar.id), :method =\> :post

What am I doing incorrect?

---

<div class="post-metadata">

**Author:** ![flamingsole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@flamingsole](https://www.ruby-forum.com/u/flamingsole)\
**Post date:** [August 3, 2010, 11:26pm UTC](https://www.ruby-forum.com/t/restfull-routes-link-to-and-additional-paramters/192666/2 "2010-08-03T23:26:30Z")

</div>

Jonathan S. wrote:

> I am trying to do a link\_to with multiple to create an object.  
> Everything works until ad the second parameter in. As soon as I add the  
> second parameter, it forgets to add any information about the first one.

What do you mean, “it forgets to add any information about the first  
one”? I don’t understand what you are trying to say there.

> link\_to “create”, foos\_path(@foo, :bar\_id =\> @bar.id), :method =\> :post  
> What am I doing incorrect?

You are aware that links should be GET requests and not POST requests,  
right? GETs should be safe.

[URIs, Addressability, and the use of HTTP GET and POST](http://www.w3.org/2001/tag/doc/whenToUseGet.html)

Also you should think about “Progressive Enhancement” and what happens  
when people do not have have Javascript available. Using :method  
requires Javascript to create a form on the fly in memory. It is just  
a normal GET otherwise.

But as to your problem, I am not sure. It works for me. I just  
jigged up a test case of your example and I was able to use that same  
syntax just fine.

I suggest enclosing the link\_to with parenthesis. That can sometimes  
enable the error to be more visible with a different ruby message.

\<%= link\_to(“create”, foos\_path(@foo, :bar\_id =\> @bar.id), :method =\>  
:post) %\>

Not sure but a shot in the dark. Make sure the parameter is a string  
with to\_s.

\<%= link\_to(“create”, foos\_path(@foo, :bar\_id =\> @bar.id.to\_s),  
:method =\> :post) %\>

Are you including default Javascript libraries? IIRC that is needed.  
Not sure though.

\<%= javascript\_include\_tag :defaults %\>

Good luck!

Bob
