Modify *_filter methods to allow stacking of declarations?

View: New views
2 Messages — Rating Filter:   Alert me  

Modify *_filter methods to allow stacking of declarations?

by Ryan Angilly :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey guys,

I'd like to hear people's opinions on modifying the filter class methods such that we could stack declarations.  Take the following setup as an example:

class DashboardController < ApplicationController
  include Filters
  include RssPresenter
  before_filter :get_user, :only => [:index]

  def some_action_that_doesnt_require_user
  end
end

module Filters
  def get_user
    @user = User.find(params[:id])
  end

  private :get_user
end

module RssPresenter
  def self.included(base)
    base.before_filter :get_user, :only => [:rss]
  end

  def rss
    #stuff
  end
end


Currently, get_user will not be called on RssPresenter#rss because the before_filter call in DashboardController overrides the base.before_filter in RssPresenter.  Rewriting RssPresenter like this:

module RssPresenter
  def self.included(base)
    base.before_filter :get_user
  end

  def rss
    #stuff
  end
end

will not work because then get_user will get called on every action in DashboardController.

Let me know what you guys think of this, and I'll work on a patch if you'd like.

Thanks,
Ryan

--~--~---------~--~----~------------~-------~--~----~
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@...
To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Modify *_filter methods to allow stacking of declarations?

by Ryan Angilly :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Should probably clarify what I'm actually proposing :)

I'd like it to look like this:

class DashboardController < ApplicationController
  include Filters
  include RssPresenter
  before_filter :get_user, :on => [:index]

  def some_action_that_doesnt_require_user
  end
end

module Filters
  def get_user
    @user = User.find(params[:id])
  end

  private :get_user
end

module RssPresenter
  def self.included(base)
    base.before_filter :get_user, :on => [:rss]
  end

  def rss
    #stuff
  end
end


Where specifying an :on parameter would add actions to the action list for the given filter method.



On Fri, Oct 23, 2009 at 11:52 AM, Ryan Angilly <angilly@...> wrote:
Hey guys,

I'd like to hear people's opinions on modifying the filter class methods such that we could stack declarations.  Take the following setup as an example:

class DashboardController < ApplicationController
  include Filters
  include RssPresenter
  before_filter :get_user, :only => [:index]

  def some_action_that_doesnt_require_user
  end
end

module Filters
  def get_user
    @user = User.find(params[:id])
  end

  private :get_user
end

module RssPresenter
  def self.included(base)
    base.before_filter :get_user, :only => [:rss]
  end

  def rss
    #stuff
  end
end


Currently, get_user will not be called on RssPresenter#rss because the before_filter call in DashboardController overrides the base.before_filter in RssPresenter.  Rewriting RssPresenter like this:

module RssPresenter
  def self.included(base)
    base.before_filter :get_user
  end

  def rss
    #stuff
  end
end

will not work because then get_user will get called on every action in DashboardController.

Let me know what you guys think of this, and I'll work on a patch if you'd like.

Thanks,
Ryan


--~--~---------~--~----~------------~-------~--~----~
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@...
To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---