Forum: Ruby on Rails Adding before_filter from inculded Module

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4a9e00598cbbb475cc9e117360e07fcf?d=identicon&s=25 Christoph Olszowka (Guest)
on 2007-06-24 03:06
(Received via mailing list)
Hi,

so I've got my nice pagination module that I'm mixing into
application.rb. It all works really nice, except for my before_filter
definition: When I put it into the module, my app starts throwing 500-
errors. Obviously I can't add this from a module the way I'm calling
it directly in application.rb or specific controllers, because the
before_filter class method seems to be out of scope or something. Is
there a way to achieve this some other way?

Thanks in advance and greetings,
Christoph
4a9e00598cbbb475cc9e117360e07fcf?d=identicon&s=25 Christoph Olszowka (Guest)
on 2007-07-19 00:46
(Received via mailing list)
Really no ideas on how to do this?

On 24 Jun., 03:05, Christoph Olszowka <musicpo...@googlemail.com>
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2007-07-19 07:16
Christoph Olszowka wrote:
> so I've got my nice pagination module that I'm mixing into
> application.rb. It all works really nice, except for my before_filter
> definition: When I put it into the module, my app starts throwing 500-
> errors. Obviously I can't add this from a module the way I'm calling
> it directly in application.rb or specific controllers, because the
> before_filter class method seems to be out of scope or something. Is
> there a way to achieve this some other way?

Hard to say what's going on w/o seeing any of your code.  This is how I
would do it:

module Foo
  def self.included(base)
    base.before_filter :bar
  end

  def bar
    # ...
  end
end


--
Josh Susser
http://blog.hasmanythrough.com
564069ff86ab396c1e79ba34231d154a?d=identicon&s=25 Artur Małecki (seeweer)
on 2012-06-18 20:34
You can also use ActiveRecord::Concer and put model related methods to
included block.

For example:


require 'active_support/concern'

module Foo
  extend ActiveSupport::Concern

  included do
    before_filter :bar
  end
end


---
Artur Małecki
http://seeweer.com
This topic is locked and can not be replied to.