About
fv_2007
Agile innovative developer with deep insight into lots of platforms, technologies and protocols. Absolute “early adopter” in Web 2.0 technologies and more. Large professional network and eagerly talking about architecture, strategy, design patterns, restful ressources, object-oriented thinking and modeling languages such as PML. Special interest in programminglanguages constructs, knowledge on languages like Smalltalk, Erlang, Java, Clojure, Scala, Ruby... read more
Comments
Language

Ruby response_to method February 02, 2007 06:08 over 5 years ago

Denne Ruby on Rails metode henter alle order på et produkt og retunere i XML, html eller javascript til brug for Ajax. cool


@product = Product.find 1234
@orders = product.orders

response_to do |format| format.rhtml format.rxml format.rjs end

This is beautiful to look at! You can tell exactly what it does.
The code has 3 methods, xml, javascript and html, that each take closures.
Each method can selectively call its closure based on the contents of the http accept header!


By Frank Vilhelmsen - 1 tag: rails - Add comment