Re: [Radiant] Extend ApplicationHelper
I have follow the code in help extension. But it doesn't seem to work. I am using Radiant 0.9.1. I have a a common_helper.rb under my extension my_extension/app/helpers/common_helper.rb. So under class MyExtensionExtension < Radiant::Extension def activate ApplicationController.class_eval{ helper CommonHelper } end end But the methods in CommonHelper is not visible in the view. I always get undefined methods error for ActionView::Base. However i move the code to the following then it works. I suspect it is the loading order problem. require_dependency 'application_controller' ApplicationController.class_eval{ helper CommonHelper } class MyExtensionExtension < Radiant::Extension def activate end end I saw some extension directly include the Helper for ActionView::Base and it works. ActionView::Base.send :include, ShareLayouts::Helper
Re: [Radiant] Extend ApplicationHelper
On Tue, Oct 11, 2011 at 12:15 PM, Shanison wrote: > You have the following application helper > module ApplicationHelper > def method_a > end > end > Then if you have other helper > module OtherHelper > def b > method_a # i can call method a here > end > end > I am not sure how this actually works since module has not inheritance. So > my question is if I didn't extend the applicationhelper module, but create a > new module for it, let's say UserHelper. Then in any other helper module, i > need to include this UserHelper module if the helper module needs to use > some of the codes in it. Hope i get myself clear. Have you tried my suggestion? Just make another helper and include it in ApplicationController. Here's a simple irb session exemplifying what happens if you add a module to a class after the class is defined: $ irb >> module Greeter >> def hello >> 'hello' >> end >> end => nil >> class Thing >> include Greeter >> end => Thing >> module More >> def more >> "more with #{hello}" >> end >> end => nil >> Thing.class_eval { include More } => Thing >> thing = Thing.new => # >> thing.hello => "hello" >> thing.more => "more with hello" >> -- OOP, DCI, and Ruby http://www.saturnflyer.com/blog/jim/2011/10/04/oop-dci-and-ruby-what-your-system-is-vs-what-your-system-does/ Jim Gay Saturn Flyer LLC http://www.saturnflyer.com 571-403-0338
Re: [Radiant] Extend ApplicationHelper
You have the following application helper module ApplicationHelper def method_a end end Then if you have other helper module OtherHelper def b method_a # i can call method a here end end I am not sure how this actually works since module has not inheritance. So my question is if I didn't extend the applicationhelper module, but create a new module for it, let's say UserHelper. Then in any other helper module, i need to include this UserHelper module if the helper module needs to use some of the codes in it. Hope i get myself clear.
Re: [Radiant] Extend ApplicationHelper
On Tue, Oct 11, 2011 at 11:40 AM, Shanison wrote: > Thanks for the reply. However if i create new helper module, it won't behave > as application_helper. So there is not method inheritance. Then for other > modules that i need to use some codes inside this helper, i need to include > the new module? Modules do not have inheritance. Let's change the conversation then. What exactly do you want to do? -JIm -- OOP, DCI, and Ruby http://www.saturnflyer.com/blog/jim/2011/10/04/oop-dci-and-ruby-what-your-system-is-vs-what-your-system-does/ Jim Gay Saturn Flyer LLC http://www.saturnflyer.com 571-403-0338
Re: [Radiant] Extend ApplicationHelper
Thanks for the reply. However if i create new helper module, it won't behave as application_helper. So there is not method inheritance. Then for other modules that i need to use some codes inside this helper, i need to include the new module?
Re: [Radiant] Extend ApplicationHelper
On Sun, Oct 9, 2011 at 9:09 AM, Shanison wrote: > Hi all, > > I have some methods that needs to be used by all helpers in the > extensions. So I need to add some methods to ApplicationHelper. I > can't just create the application_helper.rb in my extensions, it will > just overwrite the application_helper in radiant and only my own > methods in the application_helper.rb is visible. > > I tried to do ApplicationHelper.send(:include, > MyExtensions::ApplicationHelperExtensions) when activating the > extension. However, those methods in ApplicationHelperExtensions are > also not visible to my helpers. I tried to use rails console and do > ApplicationHelper.instance_methods.include?('my_method_name') > > It returns true. I don't understand why my helpers are not able to > pick up those methods. Any help is appreciated. Thanks. > I don't think you need to extend the ApplicationHelper, you just need to include a new helper into ApplicationController Does this example from the Help extension work for you? https://github.com/saturnflyer/radiant-help-extension/blob/master/help_extension.rb#L53 -- OOP, DCI, and Ruby http://www.saturnflyer.com/blog/jim/2011/10/04/oop-dci-and-ruby-what-your-system-is-vs-what-your-system-does/ Jim Gay Saturn Flyer LLC http://www.saturnflyer.com 571-403-0338
[Radiant] Extend ApplicationHelper
Hi all, I have some methods that needs to be used by all helpers in the extensions. So I need to add some methods to ApplicationHelper. I can't just create the application_helper.rb in my extensions, it will just overwrite the application_helper in radiant and only my own methods in the application_helper.rb is visible. I tried to do ApplicationHelper.send(:include, MyExtensions::ApplicationHelperExtensions) when activating the extension. However, those methods in ApplicationHelperExtensions are also not visible to my helpers. I tried to use rails console and do ApplicationHelper.instance_methods.include?('my_method_name') It returns true. I don't understand why my helpers are not able to pick up those methods. Any help is appreciated. Thanks.