Permalink
Browse files

README updates

git-svn-id: https://svn.thoughtbot.com/plugins/what@362 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
1 parent 7609bd7 commit e269f3d5aa80c7ccf00f06ac6b1119fa64862e56 dcroak committed Feb 20, 2008
Showing with 35 additions and 34 deletions.
  1. +35 −34 README
View
@@ -2,78 +2,79 @@ 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?
+for the native Rails mime-types. You now have these methods
+available from your controllers:
+
+request.format.atom?
+request.format.css?
+request.format.csv?
+request.format.html?
+request.format.ics?
+request.format.js?
+request.format.json?
+request.format.multipart_form?
+request.format.rss?
+request.format.text?
+request.format.url_encoded_form?
+request.format.xml?
+request.format.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
+# config/initializers/mime_types.rb
+
+Mime::Type.register 'text/iphone', :iphone
+
+# app/controllers/what_controller.rb
-__app/controllers/what_controller.rb__
class WhatController < ApplicationController
- before_filter :csv?,
- :blah?
+ before_filter :csv?, :iphone?
def index
render :text => 'index'
end
+ protected
+
def csv?
if request.format.csv?
- render :text => 'csv' and return false
+ redirect_to login_url
end
end
- def blah?
- if request.format.blah?
- render :text => 'blah' and return false
+ def iphone?
+ if request.format.iphone?
+ redirect_to login_url
end
end
end
What is especially powerful in combination with When.
-__app/controllers/what_controller.rb__
+# app/controllers/what_controller.rb
+
class WhatController < ApplicationController
- before_filter :csv,
- :if => :csv?
- before_filter :blah,
- :if => lambda {|controller| controller.request.format.blah?}
+ before_filter :login, :if => :csv?
+ before_filter :login, :if => lambda { |controller| controller.request.format.iphone? }
def index
render :text => 'index'
end
- def csv
- render :text => 'csv' and return false
- end
+ protected
def csv?
request.format.csv?
end
- def blah
- render :text => 'blah' and return false
+ def login
+ redirect_to login_url
end
end

0 comments on commit e269f3d

Please sign in to comment.