Charlie White
Charlie White

Reputation: 355

Rails, Restfully Parameterize New Action

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

Upvotes: 0

Views: 389

Answers (1)

Omar Qureshi
Omar Qureshi

Reputation: 9093

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]

Upvotes: 2

Related Questions