I have some calculations in a module that is under the /lib folder - but when using require the action of the module is not found in the controller. Does anyone have an example of the correct syntax to get this working. Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 26, 2007, at 9:19 AM, john wrote:> I have some calculations in a module that is under the /lib folder - > but when using require the action of the module is not found in the > controller. Does anyone have an example of the correct syntax to get > this working.It should work, and if the name of the file follows Rails conventions you don''t even need an explicit require. You may be overlooking something in your very Ruby code, like forgetting to mixin the module in the controller, or trying to use a module method that is actually defined as an instance method. -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yeah, I know I''m missing something, that is why I was hoping for a brief code example (ie I''m not sure what is the "Rails conventions" on this. On Mar 26, 4:44 am, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Mar 26, 2007, at 9:19 AM, john wrote: > > > I have some calculations in a module that is under the /lib folder - > > but when using require the action of the module is not found in the > > controller. Does anyone have an example of the correct syntax to get > > this working. > > It should work, and if the name of the file follows Rails conventions > you don''t even need an explicit require. > > You may be overlooking something in your very Ruby code, like > forgetting to mixin the module in the controller, or trying to use a > module method that is actually defined as an instance method. > > -- fxn--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi John, Did you miss out any of the steps below? calculator.rb -------------- module Calculator def sum(a,b) a+b end end config/environment.rb or test_controller.rb --------------------------------------- require ''calculator'' test_controller.rb ------------------ class TestController < ActiveRecord::Base include Calculator def test_sum # you should be able to call sum here @sum_value = sum(1,4) end end Herry -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of john Sent: 26 March 2007 15:19 To: Ruby on Rails: Talk Subject: [Rails] require module in controller I have some calculations in a module that is under the /lib folder - but when using require the action of the module is not found in the controller. Does anyone have an example of the correct syntax to get this working. Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---