standard route but having errors

hey i have routes defined as,

  map.question 'question/:id', :controller => 'question', :action =>
'show'
  # Install the default route as the lowest priority.
  map.connect ':controller/:action/:id.:format'
  map.connect ':controller/:action/:id'

now im having errors trying to get any of the actions inside my
question controller.
question/new
question/edit
etc... all come up with errors trying to send it to the action 'show'

if i reverse the order:

  map.connect ':controller/:action/:id.:format'
  map.connect ':controller/:action/:id'
  map.question 'question/:id', :controller => 'question', :action =>
'show'

my actions work but then if i use question/2 it says
Unknown action

No action responded to 2

how do i route my urls properly for this to work?

hey i have routes defined as,

  map.question 'question/:id', :controller => 'question', :action =>
'show'
  # Install the default route as the lowest priority.
  map.connect ':controller/:action/:id.:format'
  map.connect ':controller/:action/:id'

[..]

how do i route my urls properly for this to work?

Try :

map.question 'question/:id', :controller => 'question', :action =>
'show', :id => /\d+/
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'

    -- Jean-François.

ok cool that worked,

but why is the :id => /\d+/ needed? and what does that do ?
does it check to see if its a decimal as a parameter or something ?

yes.

when you've got this named route :
map.question 'question/:id', :controller => 'question', :action =>
'show'

with 'question/new', Rails will try to match this path with your route,
and it will be successful with params[:id] = 'new'.

If you require that the dynamic segment (:id) in the route must be in
decimal format ( :id => /\d+/), then 'question/new' will not be
recognized by the question named route, and Rails will try
with next route and so on. 'question/new' will be later recognized
by ':controller/:action/:id' route.

Requirements on route can be useful.

   -- Jean-François.

mm cos i thought rails would put preference to actions if one exists
so i thought it would work like this.

if we have 'question/123'

look for an action by the name of 123 , if not then see what other
routes we have, in this case we have
map.question 'question/:id', :controller => 'question', :action =>
'show'

if we have 'question/new'

we found an action so ignore the other routes

Not exactly. The way it works, as far as I know, is that Rails
tries to make your path recognize from routes, from the top to
the bottom, and stops when there is a match. If any routes don't
recognize your path, there's an error. If a path can be recognized
by many routes, the one with the highest priority wins (because
Rails starts at the top and stop at the first match). So the order
of your routes is important.

Also :
- in your class controller, it's possible to use a method_missing
mechanism
- it's also possible that the method doesn't exist but
as the template exists, Rails will directly render it (I never use
this mechanism but it should work)
- and in your routes.rb, you can if you want, suppress the generic
route :

map.connect ':controller/:action/:id'

because you find it permissive and you'd rather defining all the
routes 'statically'.

   -- Jean-François.

ok thanks heaps for your advice.

have good day!