Hello, I''m pulling my hair out as I can''t seem to find resolution to my simple problem, which is calling methods from controllers to helpers. in my application_controller.rb I have helper :all, which as i understand should include all helpers all the time. Then when i try to call methods in helpers i get undefined method error. Is there another place where i have to include helpers to make them available in controllers? -- Posted via http://www.ruby-forum.com/.
Helper methods are used in the template class (ActionView::Template), not controllers. If I''m reading the documentation right, putting "helper :all" in a controller makes all helpers found in app/helpers/ **/*rb available in that controller''s views. On Oct 31, 3:48 pm, Great John <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, I''m pulling my hair out as I can''t seem to find resolution to my > simple problem, which is calling methods from controllers to helpers. > > in my application_controller.rb I have helper :all, which as i > understand should include all helpers all the time. > Then when i try to call methods in helpers i get undefined method error. > > Is there another place where i have to include helpers to make them > available in controllers? > -- > Posted viahttp://www.ruby-forum.com/.
If you really want to use an existing Rails helper in your controllers, do the following : 1. add the following the following code to your application_controller (a singleton and a method): class Helper include Singleton include ActionView::Helpers::DateHelper include ActionView::Helpers::TextHelper # include other helpers end def helpers Helper.instance end 2. Use the helpers in your controller : @nice_string helpers.distance_of_time_in_words(@t1,@t2) Regards, MVCaraiman. On Oct 31, 8:48 pm, Great John <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, I''m pulling my hair out as I can''t seem to find resolution to my > simple problem, which is calling methods from controllers to helpers. > > in my application_controller.rb I have helper :all, which as i > understand should include all helpers all the time. > Then when i try to call methods in helpers i get undefined method error. > > Is there another place where i have to include helpers to make them > available in controllers? > -- > Posted viahttp://www.ruby-forum.com/.