Skip to content

Instantly share code, notes, and snippets.

@spiceee
Created November 24, 2009 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiceee/242264 to your computer and use it in GitHub Desktop.
Save spiceee/242264 to your computer and use it in GitHub Desktop.
def render(opts = {}, extra_options = {}, &block)
if opts[:to_yaml] then
headers["Content-Type"] = "text/plain;"
render :text => Hash.from_xml(render_to_string(:template => opts[:to_yaml], :layout => false)).to_yaml, :layout => false
elsif opts[:to_json] then
# headers["Content-Type"] = "text/javascript;"
render :json => Hash.from_xml(render_to_string(:template => opts[:to_json], :layout => false)).to_json, :layout => false
else
super opts, extra_options, &block
end
end
# Now, you can call something like:
respond_to do |wants|
wants.html
wants.xml { render :layout => false }
wants.yaml { render :to_yaml => "nodes/show.xml.builder" }
wants.json { render :to_json => "nodes/show.xml.builder" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment