REST best practices for customized views

I’m looking for some advice on REST best practices for providing two
different views that update the same resource. I’m working on a hotel
registration system and there are two different views that edit the
guest model.

The first one is used to take/update reservations and enter all the
basic guest information. The second one is used to check-in guest by
providing a quick update from a list of search results. The clerk can
enter room number, etc in the table and update the guest right there;
it then takes the guest back to the search page.

The problem is that both of these should do a PUT on the guest to
update the information. My question is where should those two actions
reside, and how should I handle two different redirections from the
update action?

I’ve thought about creating another model called registration that the
second case updates, but that seems a little overkill. What about a
second controller and routes with name_prefix?

Are there best practices for this situation? Any thoughts or
recommendations would be appreciated.

~Thadd

Thadd Selden
[email protected]
http://www.thaddeus.net

"Gentlemen, bring me that horizon."

On 2/10/08, Thaddeus S. [email protected] wrote:

it then takes the guest back to the search page.
Are there best practices for this situation? Any thoughts or
recommendations would be appreciated.

It seems to me that there should be three different resources here:

Guest

Reservation - created when the guest makes a reservation

RoomAssignment -created when the guest checks in.

I don’t think that making/changing a reservation, or checking in or
out should change the guest.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I agree with Rick, but the problem itself is interesting, how to
handle a situation where you have more than one action for one
resource - I used this solution:

map.resources :events, :member => {:show2 => :get}

because I had two completely different actions (show and show2 in
events_controller) for one event.

Any other solution would be appreciated…

Philipp

I think that you need to sharpen your use cases to clarify the object
each user has for the view. The second screen is described as being
used by both a clerk and a user/guest. This may have been a casual
mistake but it sounds like you’re not clear on the specifics…
getting that clarity will help.

From what is posted, it sounds like the goal of the first view is to
create or update a Reservation. It sounds very much like the view
should be focused on the reservation and any guest fields would be
handled through the Reservation. That is, you’d put/post to the
ReservationsController and have something like this…

def update
@reservation = Reservation.find(params[:id])
if @reservation.update_attributes(params[:reservation]) &&
@reservation.guest.update_attributes(params[:guest])

end

The second screen really sounds like it’s no different. A clerk looks
up ‘Today’s Reservations’ and finds Mr. Smith’s reservation in the
index. He keys the room assignment, Mr. Smith’s local contact number,
etc into the grid and click’s the ‘Assign Room’ button on the row.
But ‘assign room’ is really just updating the Reservation through the
ReservationsController. There is no need to use the Guest controller
at all. From the UI perspective the Reservation resource includes a
‘guest’ attribute for which it proxies updates.