ronald.evangelista
2008-Jun-05 08:19 UTC
how to add a method without coding it directly into app?
i''m missing something here. how would I code this outside the application to be shared with other Camping apps? module Blog::Controllers module AuthenticationHelper def self.included(base) class << base define_method :authenticate do |*a| a.each do |meth| if method_defined?(meth.to_s) alias_method "__#{meth}__", meth class_def(meth) do |*a| @state.Back=@env.REQUEST_URI return redirect(Login) if @state.blank? or @state.user_id.nil? send("__#{meth}__", *a) end end end end end end end end any hints? thanks!
Bluebie, Jenna
2008-Jun-05 08:21 UTC
how to add a method without coding it directly into app?
Change Blog::Controllers to Camping::Controllers and require it before Caming.goes :somewhere_else On 05/06/2008, at 6:19 PM, ronald.evangelista wrote:> i''m missing something here. > how would I code this outside the application to be shared with > other Camping apps? > > module Blog::Controllers > module AuthenticationHelper > def self.included(base) > class << base > define_method :authenticate do |*a| > a.each do |meth| > if method_defined?(meth.to_s) > alias_method "__#{meth}__", meth > class_def(meth) do |*a| > @state.Back=@env.REQUEST_URI > return redirect(Login) if > @state.blank? or @state.user_id.nil? > send("__#{meth}__", *a) > end > end > end > end > end > end > end > end > > any hints? thanks! > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list
ronald.evangelista
2008-Jun-05 08:53 UTC
how to add a method without coding it directly into app?
..an oversight. :-) modified slightly to work: class_def(meth) do |*a| controller_module = self.class.name.split(/::/) controller_module.pop controller_module << :Login # maybe this could be passed as an arg too controller_module=controller_module.join("::").constantize @state.Back=@env.REQUEST_URI return redirect(controller_module) if @state.blank? or @state.user_id.nil? send("__#{meth}__", *a) end thanks for the speedy reply!