Topic: confused about restul routing

new to webdevelopment, rails and ruby

i'm currently learning rails from a book foundation rails 2. there is a piece of code i can't figure out:

map.lost '/lost', :controller => 'toys', :action => 'new', :type => 'LOST'
map.found '/found', :controller => 'toys', :action => 'new', :type => 'FOUND'

i understand that i'm mapping /lost and /found to toys/new, but i don't understand the :type parameter. none of my models have it. my current thinking is that the request will have :type in its parameter hash, i.e. params[:type] = 'LOST' or params[:type] = 'FOUND'. if i'm correct then would it mean that i can put my own data into the params hash? i.e

map.mypath1 '/mypath1', :mycontroller => 'controller', :action => 'myaction', :mytype1 => 'somedata1', :mytype2 => 'somedata2'
map.mypath2 '/mypath1', :mycontroller => 'controller', :action => 'myaction', :mytype3 => 'somedata3', :mytype4 => 'somedata4'

any help is appreciated

Re: confused about restul routing

Your understanding is correct.

And yes,  you could hard code specific data into your routes if you wish.  It's probably not a good idea,  but you can do it.

The first example you posted is a reasonable use of a hard coded parameter.

The second example wouldn't work because the two routes are identical, '/mypathl', the second one would never get fired because the first one will match that route.  Plus a bunch of other stuff that is wrong with it.

map.mypath1 '/mypath/:mytype1/:mytype2', :controller=>'application' , :action=>'myaction', :mytype1=>nil, :mytype2=>nil

With the above route,  all these urls would match:


def myaction
  if params[:mytype2]
    puts 'third version of route'
  elsif params[:mytype1]
    puts 'second version of route'
    puts 'first version of route'

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.