Topic: Another Question Regarding REST

This may be more about my application design than REST.

I'm looking to refactor an existing application to take advantage of REST. Right now, I'm using one controller to handle the CRUD operations for three sibling STI models (journal, book and database all inherit from item). So in my routes.rb I've got something like:

  map.journal_list  'journals/list/:letter',  :controller => "items", :action => 'list', :type => 'journal'
  map.database_list 'databases/list/:letter', :controller => "items", :action => 'list', :type => 'database'
  map.book_list     'books/list/:letter',     :controller => "items", :action => 'list', :type => 'book'

The single controller uses the :type param to programmatically decide which Model to use. It might be the entirely wrong thing to do (please enlighten me). But, it seemed like good DRY practice and appears to work well in my case.

In order to convert that to REST, I [i]think[i] I could do something like:

 map.resources :journals, :controller => 'links', :name_prefix => "journal_"

But that doesn't seem to work and in any case doesn't provide a means for passing parameters from the route definition (ala :type => ...).

Am I way out in left field here? It looks like the only way to use REST is to refactor my single controller to separate controllers for each of the models. Any thoughts? Thanks.

Re: Another Question Regarding REST

To partially answer my own question, REST works out just fine if I refactor along the lines of Derek Siver's Shared-Controller Example (a cleaner variation of what I'd been doing).

Re: Another Question Regarding REST

I have been having trouble converting my controllers to REST too. In fact, I pretty much gave up. If you got the time, I'd love to see what you did to solve your issues. My issues were different, but in general it seems to be hard to customize the routes for RESTful controllers.

But since Rails in the words of DHH is "opinionated software", I suppose it's entirely possible that you are not meant to change the routes of RESTful controllers very much. The specific routes/actions seem to be the main thing - if not the only thing - that defines REST. If that's true, it simply means to me that not all controllers will benefit from being refactored into REST.

However, I still have a hard time understanding all the fuzz about REST. I'd love to see more real-world examples that clearly show the benefits. If anybody know of such good examples, please post some pointers. smile