views:

59

answers:

1

I have a Scouts model that requires two actions in addition to the standard REST actions, check_in and check_out. So I have my route as:

resources :scouts do
  member do
    get 'check_in'
    get 'check_out'
   end
end

But I need to display the show.html to the user, with a link to check_in the Scout or check_out the scout. In order to utilize the same show.html view and keep only one show action in ScoutsController, I pass ?mode=check_in or ?mode=check_out appended to the url to designate this is not a regular show action and thus display "Check In" and "Check Out" links.

I thought about creating a check_in and check_out resource, but that doesn't seem to fit the model of REST as checking in/out is an action and not a resource.

Is there a better way to handle this RESTfully?

Update: The mode comes from different users with differing agendas (i.e. workflows). One user may need to show and edit Scout data, while another will only be performing check_in activities.

But, the user that is performing check_in activities may need to edit. For example, the user performing check_in activities may spot an error in Scout data, fix it by editing, and return to their check_in activity. Passing the mode allows me to determine the users agenda. Also, adding the mode allows me to use only one show/edit/etc view and just display the appropriate links based on it.

I could put mode in the session hash. Either way, same result.

The benefit is a very simple user interface (for very simple users).

Seems to me that the Scout is the resource and check_in and check_out are the actions. But using the mode seems awkward. But maybe it really is the best way. That's my question.

A: 

It would appear to me that check_in and check_out relate to a registration, so I would think that you need another resource for registrations. check_in would map to create and check_out would map to destroy.

  resources :registrations

  match 'check_in', :to => "registrations#create", :as => "check_in"
  match 'check_out', :to => 'registrations#destroy', :as => "check_out"
cowboycoded
A Scout is a person, like an attendee at a conference. There will be a registration desk where the Scout will check_in. Check_out is for disqualified Scouts. Check_in and check_out are actions. The Scout model has a `checked_in` flag for the status.
Karl
I updated my answer, but I am still unclear on why you need to pass the mode= in the URL if the scout has the flag. If the flag is set in the scout model, couldnt you just check to see if that flag is set based on which scout you are looking at?
cowboycoded
No, see update.
Karl
that makes more sense to me now. If you think Scout should be the resource, then I would go with that. In my opinion, it is sometimes overkill to force all actions to be "perfectly" RESTful.. it can make you create resources that feel unnatural as seems the case in your design. Ultimately, it comes down to cost/benefit. I think your solution works and is it really worth it to try to figure out the "perfect" RESTful way, when your method is understandable. As far as the mode goes, I see nothing wrong with that. I pass parameters if I need a slightly different views for show.
cowboycoded
I guess the only thing I would recommend is changing the member resource methods to "put", since you are updating the flag (I think??) in the scout model with check_in and check_out
cowboycoded