4 # ... important code ...
6 # respond_to do |wants|
7 # wants.html { render :something }
8 # wants.text { "Just some text." }
9 # wants.yaml { "Something neat!".to_yaml }
10 # wants.xml { "Also, XML.".to_xml }
17 yield response = Response.new(request.env["HTTP_ACCEPT"])
18 headers 'Content-Type' => response.content_type
23 attr_reader :body, :content_type
24 def initialize(accept) @accept = accept end
27 :yaml => %w[application/yaml text/yaml],
28 :text => %w[text/plain],
29 :html => %w[text/html */* application/html],
30 :xml => %w[application/xml],
31 :json => %w[application/json]
34 def method_missing(method, *args)
35 if TYPES[method] && @accept =~ Regexp.union(*TYPES[method])
36 @content_type = TYPES[method].first
37 @body = yield if block_given?