Extended Mime Responder functionality

jcast
Fri, 07 Mar 2008 19:47:08 -0000

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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---