# You can pass multiple parameters using link\_to? anything bad

**URL:** <https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236>\
**Category:** Rails\
**Created:** [August 13, 2006, 8:24pm UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236 "2006-08-13T20:24:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 13, 2006, 8:24pm UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/1 "2006-08-13T20:24:44Z")

</div>

i just found out i can pass mutiple parameters from views like

\<%= link\_to doctype.name, :action =\> “show\_towns”, :id =\> doctype.name,  
:id2 =\> doctype.id%\>

silly me, i always had the impression that i could only pass 1. i guess  
i dont have to use sessions after all for my site. is there anything  
wrong with this?

basically instead of the user filling out forms(drop down boxes, radio  
boxes etc), i just what them to click on links that gets passed to the  
contoller etc…and depending on what the selected, that will be used  
for the query. is there anything wrong with this approach?

thanks.

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 13, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/2 "2006-08-13T22:04:37Z")

</div>

koloa wrote:

> i just found out i can pass mutiple parameters from views like
> 
> \<%= link\_to doctype.name, :action =\> “show\_towns”, :id =\> doctype.name,  
> :id2 =\> doctype.id%\>
> 
> silly me, i always had the impression that i could only pass 1. i guess  
> i dont have to use sessions after all for my site. is there anything  
> wrong with this?
> 
> basically instead of the user filling out forms(drop down boxes, radio  
> boxes etc), i just what them to click on links that gets passed to the  
> contoller etc…and depending on what the selected, that will be used  
> for the query. is there anything wrong with this approach?
> 
> thanks.

it’s a fine approach, but just remember that if you don’t define what to  
do with :id2 in routes.rb, then your url will look something like this:

/controller/show\_towns/town\_name?id2=town\_id

~js

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 14, 2006, 1:14am UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/3 "2006-08-14T01:14:30Z")

</div>

hi james, thanks for the reply. what way should it look like? any  
samples of what you mean? i am very new to web development.

thank you.

James Schementi wrote:

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 14, 2006, 2:33am UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/4 "2006-08-14T02:33:56Z")

</div>

koloa wrote:

> hi james, thanks for the reply. what way should it look like? any  
> samples of what you mean? i am very new to web development.

It’s fine if the URL looks like that, but if you want a clean url you’ll  
have to add a rewrite rule in “routes.rb” to look something like this:

map.connect ‘:controller/:action/:id2/:id’

this will turn that link i wrote above into  
/controller\_name/show\_towns/town\_name/town\_id

I suggest renaming :id2 to :name or something like that so it makes  
sense.

[Peak Obsession](http://manuals.rubyonrails.com/read/chapter/65) - this is a good  
explanation of what routes are and why to use them.

~js

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/5 "2006-08-15T14:19:51Z")

</div>

Not really anything technically wrong with the approach but I’ll mention  
a  
few things that jump out right away:

There is a limit to how long a URL can be… I believe 255 characters  
max.  
Also, you don’t want anything in there that can be private data, like  
passwords.

Also keep in mind that it’s easier for people to manipulate URLs than it  
is  
to manipulate form data (neither is really that hard) so you may have  
users  
‘exploring’ around your site more than normal.

I don’t recommend this approach though because it’s really not that  
flexible. See how far you get though.

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 15, 2006, 2:37pm UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/6 "2006-08-15T14:37:44Z")

</div>

hi brian thanks. since all my table information is public, i guess  
security is not a major issue?

i am just planning on building a little directory for my town so people  
can search for doctors in the area.

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 15, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/7 "2006-08-15T16:33:06Z")

</div>

Brian H. wrote:

> There is a limit to how long a URL can be… I believe 255 characters  
> max.

??? This isn’t true (at least outside the rails world). Most browsers  
support URL lengths in the thousands of characters…

Is their some internal Rails limit that I am not aware of?

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [August 15, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/you-can-pass-multiple-parameters-using-link-to-anything-bad/102236/8 "2006-08-15T17:47:43Z")

</div>

J Amiel wrote:

> Brian H. wrote:
> 
> > There is a limit to how long a URL can be… I believe 255 characters  
> > max.
> 
> ??? This isn’t true (at least outside the rails world). Most browsers  
> support URL lengths in the thousands of characters…

[http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html](http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html)

" The HTTP protocol does not place any a priori limit on the length of a  
URI. Servers MUST be able to handle the URI of any resource they serve,  
and SHOULD be able to handle URIs of unbounded length if they provide  
GET-based forms that could generate such URIs. A server SHOULD return  
414 (Request-URI Too Long) status if a URI is longer than the server can  
handle (see section 10.4.15).

```
  Note: Servers ought to be cautious about depending on URI lengths
  above 255 bytes, because some older client or proxy
  implementations might not properly support these lengths.

```

"
