[uf-rest] RESTified Rails Controller (take 2)

Peter E Williams pezra at barelyenough.org
Fri Feb 3 14:58:03 PST 2006


Dan Kubb wrote:

> Once I get it working and tested I'll package it up as a plugin.

Sweet.

> Nothing rock solid yet. I do know I'd like to try to keep the
> controller code the same regardless of the representation. Any
> view specific code would likely be placed in the template or in a
> helper library. I do know I'll probably use a form of Content
> Negotiation to choose the view, where the Accept* headers will be
> used to decide what representation to return.

Perhaps something like the following would work:
  resource_for :entity do
    get(:representations => {'text/html' => 'show.rhtml', 
'application/atom+xml' => 'show-atom.rxml'})
  end

You could use the quality values in the accept header to determine which 
one to use.  You would, of course, want to handle the normal case of 
having only one representation for a resource without forcing the 
developer to specify that representation.  You could probably just use 
the current view finding behavior in that case.

> All the negotiation was done before the controller's action was
> even executed so if the client asked for representations that the
> server couldn't output, a 406 Not Acceptable exception was
> returned and no action was executed.

That would be definitely be nice.

Peter



More information about the microformats-rest mailing list