Good notes posted by rubymaverick
RSS feed
rubymaverick -
June 30, 2008
12 thanks
rubymaverick -
June 26, 2008
9 thanks
Rails defined Mime Types
Here are all the default Rails Mime Types:
"*/*" => :all "text/plain" => :text "text/html" => :html "application/xhtml+xml" => :html "text/javascript" => :js "application/javascript" => :js "application/x-javascript" => :js "text/calendar" => :ics "text/csv" => :csv "application/xml" => :xml "text/xml" => :xml "application/x-xml" => :xml "text/yaml" => :yaml "application/x-yaml" => :yaml "application/rss+xml" => :rss "application/atom+xml" => :atom "application/json" => :json "text/x-json" => :json
rubymaverick -
June 26, 2008
9 thanks
Default Mime Types
This module sets up all the default mime-types. Here they are:
"*/*" => :all "text/plain" => :text "text/html" => :html "application/xhtml+xml" => :html "text/javascript" => :js "application/javascript" => :js "application/x-javascript" => :js "text/calendar" => :ics "text/csv" => :csv "application/xml" => :xml "text/xml" => :xml "application/x-xml" => :xml "text/yaml" => :yaml "application/x-yaml" => :yaml "application/rss+xml" => :rss "application/atom+xml" => :atom "application/json" => :json "text/x-json" => :json
rubymaverick -
June 25, 2008
13 thanks
How to test different responses in controller tests/specs
When you want to write a controller test or spec (rspec) to test out a different response type other than html, just set the HTTP_ACCEPTS header like so before the request:
@request.env['HTTP_ACCEPT'] = "application/rss" post :create, :blog => {}
rubymaverick -
June 25, 2008
4 thanks
Custom MIME Type
After you register a custom Mime::Type like stated above, you can do:
respond_to do |format| # .jpg corresponds to the second argument passed to #register # Mime::Type.register "image/jpg", :jpg format.jpg { ...do something here... } end