views:

149

answers:

2

Hi All,

I have a html table which consists of columns for days, and rows for hours of the day. I intend this to be a UI widget, similar to the commonly seen calendar date picker.

Clicking on a particular cell of the table would select that date and time for creating a new reservation.

I was considering using a url to represent this selection such as,

http://jupiter.local/reservations/new/2009-09-10/1200/1300

or

http://jupiter.local/reservations/new/date/2009-09-10/start-time/1200/end-time/1300

Is this a valid approach?

I have read a little about rest, however I still don't get it, except for the obvious example used for showing how to edit a blog record. e.g. blog/posts/23/edit

Currently while playing around with the app, I input the details via form fields, however the date-time select widget will make things much easier to use.

The (current) plan is to render out a series of urls for the hours which are available. If a slot is already booked, then no url is rendered. Of course I would validate the input as well. To begin with I will assume that a single hour slot is all that can be booked.

I see that websites such as airlines tend to render out a series of urls with a unique code. I expect this requires a session to keep track of these unique id's.

I am looking for some guidance on the approach as I have not designed something like this before and it is primarily intended as a learning experience.

Thanks

A: 

I think as long as you map your controller actions to the correct http verbs you're on the right track. Some of my controllers don't implement every verb and some controllers overload verbs - not a huge deal imo.

I think you just want to make the new action a little more context aware. For example let's say you want to get /reservations/new working with or without parameters. If parameters are passed in, you can hide the start date/time picker and stuff the values in hidden fields. If parameters are not passed in you show the start date/time picker. You could probably use the same controller action (new) but render different versions of the view based on parameters.

Andy Gaskell
Thanks Andy, I will try and read up on that.
Rails Fan
+1  A: 

I'd say you are overcomplicating a bit the RESTful routes. A REST URI emphasizes on working with resources. A reservation is a resource. A Date, IMHO, it's not. It's mostly a param, and thus, you should be working with something like:

http://jupiter.local/reservations/new/?date=2009-09-10&start-hour=1200&end-hour=1300

Although, I'd try to send them using a POST method (http://jupiter.local/reservations/new)

In either way, the controller will work with params[:reservation][:date], params[:reservartion][:start-hour], etc.

It's a more simply approach.

With that, I'm guessing those are attributes mapped to a table. If not, you can easily create "virtual" attributes for the model with the

attr_accessor :date, :start-hour, :end-hour

sentence.

If you send this through AJAX (which I guess you'd using from your description), Rails will add an authentication string, and you can also add your session ID (though I think it adds it aswell).

If you need more ideas, be sure to update your question :)

Yaraher
Thanks for your answer Yaraher. I will look into this and provide an update within the next few days.
Rails Fan