I have a controller named xyzController under app/controllers I have a helper class named xyzHelper under app/helpers. Shouldn''t I be able to call methods from xyzHelper inside of xyzController without any problems? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
>From Agile Rails: "If a controller is named BlogController, it willautomatically look for a helper MODULE called BlogHelper in the file blog_helper.rb in the app/helpers directory. So the answer is yes, IF: you have a helper MODULE called ZyzHelper in the file xyz_helper.rb in the app/helpers directory. Michael
Wes Gamble wrote:> I have a controller named xyzController under app/controllers > > I have a helper class named xyzHelper under app/helpers. > > Shouldn''t I be able to call methods from xyzHelper inside of > xyzController without any problems?No. Helpers define methods that can be used from the view, not the controller. -- Philip Ross http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
Here''s my module: module ESimplyHelper def get_protocol_and_server(request) request.protocol() + request.host_with_port() end end I am trying to call get_protocol_and_server from ESimplyController. Is there something wrong with my module? Thanks, Wes Michael Trier wrote:>>From Agile Rails: "If a controller is named BlogController, it will > automatically look for a helper MODULE called BlogHelper in the file > blog_helper.rb in the app/helpers directory. > > So the answer is yes, IF: you have a helper MODULE called ZyzHelper in > the file xyz_helper.rb in the app/helpers directory. > > Michael-- Posted via http://www.ruby-forum.com/.
Philip, That''s what I thought. I think it''s confusing that you specify in the controller which helper the "view" gets to use when you use the "helper" keyword. Seems like I should be able to "include" my helper and it would work, although that would be confusing in it''s own way. Thanks, Wes Philip Ross wrote:> Wes Gamble wrote: >> I have a controller named xyzController under app/controllers >> >> I have a helper class named xyzHelper under app/helpers. >> >> Shouldn''t I be able to call methods from xyzHelper inside of >> xyzController without any problems? > > No. Helpers define methods that can be used from the view, not the > controller. > > -- > Philip Ross > http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby-- Posted via http://www.ruby-forum.com/.
Rafał Komorowski
2006-Apr-24 22:28 UTC
[Rails] Re: Controller can''t find helper?????!!!!!????
On 24/04/2006, at 23:33, Philip Ross wrote:>> Shouldn''t I be able to call methods from xyzHelper inside of >> xyzController without any problems? > > No. Helpers define methods that can be used from the view, not the > controller.I think you''re wrong, Phillip. I''m using my helper code in the controller, but since helper is a module, you must address it as a module. Example code from my controller: def index @my_controller_variable = MyControllerHelper::AClassInsideMyHelper.method(parameters) ... I use helpers to store some constants and objects, that are used both by controller and view. All of it is view-related, but controllers set or get something from those helpers. -- Rafa? Komorowski komor@mac.com GG: 4083718 <http://homepage.mac.com/komor/iblog/>
Wes Gamble
2006-Apr-24 23:31 UTC
[Rails] Re: Re: Controller can''t find helper?????!!!!!????
Rafal, How do I call a function in my module if there is no class in my module Module x def y ... end end What do I need to do in my controller in order to: 1) Get access to module X 2) Invoke method y? I keep getting errors like: undefined method `validate_and_format_url'' for ESimplyUtil:Module Thanks, Wes Rafa? Komorowski wrote:> On 24/04/2006, at 23:33, Philip Ross wrote: > >>> Shouldn''t I be able to call methods from xyzHelper inside of >>> xyzController without any problems? >> >> No. Helpers define methods that can be used from the view, not the >> controller. > > I think you''re wrong, Phillip. I''m using my helper code in the > controller, but since helper is a module, you must address it as a > module. > Example code from my controller: > > def index > @my_controller_variable > MyControllerHelper::AClassInsideMyHelper.method(parameters) > ... > > I use helpers to store some constants and objects, that are used both > by controller and view. All of it is view-related, but controllers > set or get something from those helpers. > > > -- > > Rafa? Komorowski > komor@mac.com > GG: 4083718 > <http://homepage.mac.com/komor/iblog/>-- Posted via http://www.ruby-forum.com/.
Rafał Komorowski
2006-Apr-25 00:40 UTC
[Rails] Re: Re: Controller can''t find helper?????!!!!!????
On 25/04/2006, at 01:31, Wes Gamble wrote:> How do I call a function in my module if there is no class in my > moduleSure, you can. Here''s an example from the Ruby-book: # module: module Trig PI = 3.141592654 def Trig.sin(x) puts "sinus #{x}" end def Trig.cos(x) puts "cosinus #{x}" end end # how to call a function from module: Trig.sin(1.1) Trig.cos(Trig::PI) So just change your code to: module ESimplyHelper def ESimplyHelper.get_protocol_and_server(request) request.protocol() + request.host_with_port() end end and perhaps you can use it in your controller just like in the Ruby- book: ESimplyHelper.get_protocol_and_server(request) or as in Rails way: ESimplyHelper::ESimplyHelper.get_protocol_and_server(request) Give it a try. -- Rafa? Komorowski komor@mac.com GG: 4083718 <http://homepage.mac.com/komor/iblog/>