v1.2.6 -
Show latest stable
-
2 notes
- Superclass:
Object
- 1.0.0
- 1.1.6 (0)
- 1.2.6 (38)
- 2.0.3 (0)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-1)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (1)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- 7.2.3 (2)
- 8.1.1 (0)
- What's this?
Encapsulates the notion of a mime type. Can be used at render time, for example, with:
class PostsController < ActionController::Base def show @post = Post.find(params[:id]) respond_to do |format| format.html format.ics { render :text => post.to_ics, :mime_type => Mime::Type["text/calendar"] } format.xml { render :xml => @people.to_xml } end end end
Register or
log in
to add new notes.
rob-twf -
March 11, 2009 - (>= v2.1.0)
schmidt -
November 3, 2009
2 thanks
Can also be used to conditionally apply filters
For example:
# Skip login filter if the request is for CSS before_filter :require_login, :unless => lambda { |controller| controller.request.format.css? }
Calling request.format on the controller returns a Mime::Type object, which can then be queried for mime types, other examples:
controller.request.format.html? controller.request.format.json?
0 thanks
Setting a custom Content type
The given example seems to be broken. The :mime_type option as well as the [] access on the Mime::Type class are both not working.
The following code allows the custom setting of content types as intended by the original example:
class PostsController < ActionController::Base def show @post = Post.find(params[:id]) respond_to do |format| format.html format.ics { render :text => post.to_ics, :content_type => Mime::Type.lookup("text/calendar") } format.xml { render :xml => @people.to_xml } end end end

