Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

responder method for controller

#4046

I'm developing a project in Rails 3.0 and I love the Responder functionality. I'm currently using around 4 to 5 different responders per controller, and bumped into the problem that I had to create custom Responders for different sets of functions. I had a PaginationAndSortingResponder, a SortingAndFlash responder, a PaginationAndSortingAndFlash responder, and so on.

I'd think it better to have a way to cherry-pick the responders you want in a easy way. I came up with this syntax:

class InvitationController < ApplicationController
  responder :pagination, :flash
end

This codes loads up a responder with PaginationResponder and FlashResponder. I'm currently implementing this code in ApplicationController this way:

class ApplicationController < ActionController::Base
  protect_from_forgery
  
  class << self
    def responder *responders
      if responders.any?
        responder_class = Class.new(ActionController::Responder)
        responders.each do |responder|
          responder = responder.is_a?(Module) ? responder : "#{responder.to_s.classify}Responder".constantize
          responder_class.send(:include, responder)
        end
        self.responder = responder_class
      else
        super()
      end
    end
  end
end

I'd write a patch but with the new structure I'm not sure where I should put this method. I see the responder definition now is in ActionController::MimeResponds, is this also the place I should implement this function? (if wanted, ofcourse)

Reported by Jan De Poorter · February 24th, 2010 @ 12:26 PM

State: invalid
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Jan De Poorter
    Jan De Poorter

    While using it for about 6 days I notice I'd also like this method to inherit from ApplicationController, but possibility to override. Wondering how to do this though :-)

    March 3rd, 2010 @ 09:53 AM

  2. Jan De Poorter
    Jan De Poorter

    Figured this was more of a plugin thing for now. Moved it to http://github.com/DefV/easy_responders

    March 15th, 2010 @ 03:33 PM

  3. José Valim
    José Valim
    • State changed from new to invalid
    • Milestone cleared.

    Hey, I was talking with Jeremy and we just realized the same. Although, I was thinking in merging it with my responders gem:

    http://github.com/plataformatec/responders

    Are you in mood for a patch or should I implement it myself? :)

    Regards!

    March 15th, 2010 @ 03:37 PM

  4. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM