[uf-rest] Web services, Rails-style (in 1.1)

Charlie Savage cfis at interserv.com
Mon Mar 27 19:26:53 PST 2006


Hi David,

Thanks for the quick response, and good point.  For my current usage, I 
don't run into the issue.  However, I definitely agree that you don't 
want to map template types to mime types because its too limiting.  
Instead, I think you could get some mileage out of mapping template 
extensions to mime type.  For example:

my_template.ratom  (is a builder template used for application/atom+xml)
my_template.rxml  (is a builder template used for application/xml or 
text/xml )
my_template.rxthml   (is a erb template for application/xhtml+xml, or 
could be a builder template for the same mime types)

This would require that the template type (rxml, erb) is immaterial to 
Rails as long as it can find and load the template based on its 
extension.  Right now that's not true, since the method that loads 
templates (create_template_source) does slightly different things 
depending on the template type.  That could be changed fairly easy to 
"guess" what the template is, but that is admittedly a bit kludgy (but 
retains backwards compatibility).

The other issue that you run into with mime types, as you point out, is 
that text/xml or application/xml is not particularly informative since 
it covers number of potential formats.  But you run into that issue 
regardless of the implementation.

Thanks,

Charlie


David Heinemeier Hansson wrote:
>> But why not just have active record pick the correct template?  To do 
>> this requires assigning template extensions to mime types.  For 
>> example, html goes to  .rhtml, xml goes to .xml, xhtml goes to 
>> .rxhtml, etc.  This would be easy enough to do - in fact Rails is 99% 
>> of the way there already.  And it seems in line with Rails being 
>> opinionated software.  Once you make that assumption, ActiveView can 
>> do the rest of the work.  Of course, you should be able to override 
>> that choice in the controller using the same mechanism Rails current 
>> supports.
>
> Lots of people use rxml to generate HTML. Or RSS. Or Atom. And this is 
> helpful because it allows you to do things like:
>
> respond_to do |wants|
>   wants.html { redirect_to :action => "index" }
>   wants.js
>   wants.xml do
>     headers["Location"] = url_for(:action => "show", :id => @person)
>     render :xml => @person.to_xml
>   end
> end
>
> In the face of this common requirement, I don't like to introduce a 
> binding between mime type and template types.
>
> (I do like the resource :person syntax from your other article, though 
> ;))
> -- 
> David Heinemeier Hansson
> http://www.37signals.com    -- Basecamp, Backpack, Writeboard, Tada
> http://www.rubyonrails.com  -- Web-application framework
> http://www.loudthinking.com -- Broadcasting Brain
>
>
> _______________________________________________
> microformats-rest mailing list
> microformats-rest at microformats.org
> http://microformats.org/mailman/listinfo/microformats-rest
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3166 bytes
Desc: S/MIME Cryptographic Signature
Url : http://microformats.org/discuss/mail/microformats-rest/attachments/20060327/332c968e/smime.bin


More information about the microformats-rest mailing list