I want to include helper methods included to my Camping App from by
requiring an external file but I can''t seem to include helpers from
another module.
module CampingHelpers
def self.included(base)
base::Helpers.send(:include, Helpers)
end
module Helpers
def show_test
p "test"
end
end
end
Camping.goes :CampingApp
...
module CampingApp::Helpers
include CampingHelpers
end
...
the show_test method doesn''t get included at all.
is it because of camping eval''ling to S.
any help would be appreciated.
thanks!
--
|^^^^^^^^^^^^\ .||
|NALDEVNGELSTA.___||''""|""\___,
| ________________ l | |__|__|_|)
(@!)!(@)"""""**|(@) (@)****|(@)
(?`''?.?(?`''?.?(?`''?.? . Have a Terrific Day!
.?''??)?.?''??)?.?''??)?.?
Hallo Ronald,
I observed the same problems. The only solution I could make up is
adding the methods in the included hook. Not pretty, but it works
module MyHelperModule
def self.included(base)
base.const_get(:Helpers).class_eval do
def pre_code(value)
self.pre do
self.code(value)
end
end
end
end
end
and then include MyHelperModule in your Camping app
Camping.goes :Wild
module Wild
include MyHelperModule
end
If there is a more elegant solution out there, I will be happy to hear it.
Cheers,
Gregor
On Nov 6, 2007 10:26 AM, Ronald Evangelista <ironald at gmail.com>
wrote:> I want to include helper methods included to my Camping App from by
> requiring an external file but I can''t seem to include helpers
from
> another module.
>
> module CampingHelpers
> def self.included(base)
> base::Helpers.send(:include, Helpers)
> end
> module Helpers
> def show_test
> p "test"
> end
> end
> end
>
> Camping.goes :CampingApp
> ...
> module CampingApp::Helpers
> include CampingHelpers
> end
> ...
> the show_test method doesn''t get included at all.
> is it because of camping eval''ling to S.
>
> any help would be appreciated.
> thanks!
>
>
> --
> |^^^^^^^^^^^^\ .||
> |NALDEVNGELSTA.___||''""|""\___,
> | ________________ l | |__|__|_|)
> (@!)!(@)"""""**|(@) (@)****|(@)
>
> (?`''?.?(?`''?.?(?`''?.? . Have a Terrific Day!
.?''??)?.?''??)?.?''??)?.?
> _______________________________________________
> Camping-list mailing list
> Camping-list at rubyforge.org
> http://rubyforge.org/mailman/listinfo/camping-list
>
On Tue, Nov 06, 2007 at 01:26:34AM -0800, Ronald Evangelista wrote:> I want to include helper methods included to my Camping App from by > requiring an external file but I can''t seem to include helpers from > another module.Try mixing into CampApp::Mab class directly, which will add methods to the Markaby class. class CampApp::Mab include CampingHelpers end If you want mixed-in methods to be used in controllers, mix into CampApp module. _why
The root of the problem is that a module doesn''t propagate newly included methods on classes or modules where it''s been alreay included. take : module A; def a; end; end module B; def b; end; end class C; end where A is included in B and B in C. Depending on the inclusion order, you won''t get the same result. class C; include B; end module B; include A; end C.instance_methods #=> [... "b" ... ] now... module B; include A; end class C; include B; end C.instance_methods #=> [... "a", "b", ... ] ---- end of explanation In Camping 1.5.180, you''ll have to include your module in Helpers, Views and Mab. Due to some changes in Camping-trunk, you''ll only have to include your module in Helpers and Views. -- Cheers, zimbatm
it works! thanks! -- |^^^^^^^^^^^^\ .|| |NALDEVNGELSTA.___||''""|""\___, | ________________ l | |__|__|_|) (@!)!(@)"""""**|(@) (@)****|(@) (?`''?.?(?`''?.?(?`''?.? . Have a Terrific Day! .?''??)?.?''??)?.?''??)?.?