From: Stefan Rusterholz Date: 2008-11-10T07:33:43+09:00 Subject: Re: shared-0.4.2 Ara Howard wrote: > shared :before_filters do > before_filter :foo > before_filter :bar > > def foo() end > def bar() end > end > > in app/controllers/foo_controller.rb > > class Foo < ApplicationController > include shared(:before_filters) > end > > in app/controllers/bar/controller.rb > > class Bar < ApplicationController > include shared(:before_filters) > end module SharedBeforeFilters def self.included(by) by.before_filter :foo by.before_filter :bar end def foo(); end def bar(); end end in app/controllers/foo_controller.rb class Foo < ApplicationController include SharedBeforeFilters end in app/controllers/bar_controller.rb class Bar < ApplicationController include SharedBeforeFilters end > this is absolutely not easily done with modules. I don't see the problem here. shared.rb has all > the advantages of ruby module sharing *plus* the simplicity of > completely POLS class level method sharing. > > another example, which is not easily done using modules > > in lib/shared.rb > > shared :home_controller do > before_filter :must_have_user > > def index > render 'shared/home' > end > > protected > def must_have_user() end > end > > in app/controllers/teacher/home_controller.rb > > class Teacher::HomeController < ApplicationController > include shared(:home_controller) > end > > in app/controllers/student/home_controller.rb > > class Student::HomeController < ApplicationController > include shared(:home_controller) > end > > so, in that example, we can directly setup a public method (index > action) and protected method, and call a class method. try doing that > with modules and you'll see that it's rather un-natural. module HomeController def self.included(by) by.before_filter :must_have_user end def index render 'shared/home' end protected def must_have_user() end end in app/controllers/teacher/home_controller.rb class Teacher::HomeController < ApplicationController include HomeController end in app/controllers/student/home_controller.rb class Student::HomeController < ApplicationController include HomeController end Again, I don't see the issue. But maybe I miss the obvious or something :-/ > make sense? Not sure yet. But thanks for the explanations! Regards Stefan -- Posted via http://www.ruby-forum.com/.