This project is archived and is in readonly mode.

#4046 ✓invalid
Jan De Poorter

responder method for controller

Reported by Jan De Poorter | February 24th, 2010 @ 12:26 PM | in 3.0.2

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)

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages