Using custom mime types, I've run into instances where I end up calling the same function over and over again for a specific type. After a little tweaking I came up with a monkey patch that allows to pass a default block at mimetype registration time, and allows responder block calls to take arguments. I uploaded the monkey patch so let me know your thoughts. It currently only works for ActionPack 1.13.3 but porting to Rails 2 should be easy enough. Here are a couple usage examples:
Example 1:
Environment:
Mime::Type.register "text/plain", :iphone do |controller| controller.redirect_to :format => "html" unless controller.request.env['HTTP_USER_AGENT'].to_s =~ /Mobile.*Safari/ end
Controller functionality:
respond_to do |format| format.iphone end
Example 2:
Environment:
Mime::Type.register "text/plain", :debug do |controller, level, hash> level ||= 3 text = case level ... end hash.merge({:text => text}) controller.render hash end
Controller functionality:
respond_to do |format| format.debug 1, :action => "some_action", :layout => "debug" end