You can pass multiple parameters using link_to? anything bad

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.

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

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:

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 - this is a good
explanation of what routes are and why to use them.

~js

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.

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.

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?

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

" 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.

"