Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (61 sloc) 1.3 KB
What
====
What provides boolean query methods on Mime::Type instances
for the native Rails mime-types:
atom?
css?
csv?
html?
ics?
js?
json?
multipart_form?
rss?
text?
url_encoded_form?
xml?
yaml?
... and any custom mime types that you add in any environment specific config files.
Examples
========
__config/initializers/mime_types.rb__
Mime::Type.register 'text/html', :blah
__app/controllers/what_controller.rb__
class WhatController < ApplicationController
before_filter :csv?,
:blah?
def index
render :text => 'index'
end
def csv?
if request.format.csv?
render :text => 'csv' and return false
end
end
def blah?
if request.format.blah?
render :text => 'blah' and return false
end
end
end
What is especially powerful in combination with When.
__app/controllers/what_controller.rb__
class WhatController < ApplicationController
before_filter :csv,
:if => :csv?
before_filter :blah,
:if => lambda {|controller| controller.request.format.blah?}
def index
render :text => 'index'
end
def csv
render :text => 'csv' and return false
end
def csv?
request.format.csv?
end
def blah
render :text => 'blah' and return false
end
end
Copyright (c) 2008 Dan Croak, Jared Carroll, and thoughtbot, inc. released under the MIT license
Something went wrong with that request. Please try again.