views:

209

answers:

1

Hi Everyone, I would like restfully add a parameter to the new named path.

So for example, if I had a reservation resource, i would like to use the helper route:

new_reservation_path(date)

which would create the url:

/reservations/new/2009-6-10.

I then would grab the date in my new controller using

params[:date]

and default the reservation.date field to that date. Does any know if adding a parameter like this can be done? If not, any idea's about other ways to do this elegently?

Thank you very much, Charlie

+2  A: 

Probably.

Route might want to look like:

map.new_reservation "/reservations/new/:date", :date => /\d{4}-\d{1,2}-\d{1,2}/

EDIT

You may or may not have to skip the generation of the "new" route, can't remember what Rails would do if you didn't skip it:

map.resources :reservations, :except => [:new]
Omar Qureshi
You should definitely skip it. Defining them both has given me headaches in the past.
molf
So I simplified my example because it's a nested route. What's the syntax to skip the new action of the nested route. eg, I have:map.resources :events, :has_many => :reservations :except => [???]
Charlie White
also thanks a lot for the quick help, much appreciated
Charlie White
i would put the reservations bit in a block map.resources :events do |e| e.resources :reservations ....; end
Omar Qureshi