Routes,maps, something_url, some simple questions i am sure


#1

hi,
i just started learning how to custimize my urls but i have a few
questions that im sort of unsure about.

first. if i do this.

map.detail “nj/:id”

in my view for controller ‘nj’ i can do something like this?

<%= link_to (“show me details”, detail_url(something.id)) %>

is this the same as calling link_to like this?

<%= link_to (“show me details”, “localhost:3000/nj/” + something.id) %>

what is the difference between defining map like

map.detail :action => detail, :controller => nj

vs

map.connect “nj/detail” :action => detail, :controller => ‘nj’


#2

As far as your link_to usage, yes. They’re the same. The named route is
easier to maintain codewise but a little slower [at least in the olden
days]
than writing it out by hand like you do in the second example. The
difference between those last map.connect and map.details is 1.
map.detailscreates a named route where
map.connect doesn’t and 2. You’ll need to add the mapping “nj/:id” to
map.detail.

RSL


#3

thanks rsl, its clear now.

tried to look up something_url in the rails api, but didnt know what
title to look under. wasnt sure if its an extension of url_for.