[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rails 1.0 methods in application controller vs. helper

isamura

1/27/2006 12:24:00 AM

I have several methods that can have potential use in both the
controller and view. Currently there are two copies of each method,
one in the controller and the other in the helper.

Does anyone know of another location where these methods can be
accessed by both? Thereby avoiding the duplication of code.

Thanks,

..k


5 Answers

konsu

1/27/2006 6:30:00 AM

0

Hello,

did you try to use the "require" functionality and put your methods in to a
file and just require it?

konstantin

"isamura" <oop@poo.com> wrote in message
news:drbpb4$rq2$1@domitilla.aioe.org...
>I have several methods that can have potential use in both the
> controller and view. Currently there are two copies of each method,
> one in the controller and the other in the helper.
>
> Does anyone know of another location where these methods can be
> accessed by both? Thereby avoiding the duplication of code.
>
> Thanks,
>
> .k
>
>


isamura

1/27/2006 3:15:00 PM

0

"konsu" <konsu@hotmail.com> wrote ...
: Hello,
:
: did you try to use the "require" functionality and put your methods in to a
: file and just require it?
:
: konstantin

You've reminded me to review Module and Mixins. It seems I should use
"require" and "include". But I am not sure where to place my new
module file so that both ApplicationController and ApplicationHelper
classes can "see" it. Is there a modules load PATH I should know about?

Regards,

..k

:
: "isamura" <oop@poo.com> wrote in message
: news:drbpb4$rq2$1@domitilla.aioe.org...
: >I have several methods that can have potential use in both the
: > controller and view. Currently there are two copies of each method,
: > one in the controller and the other in the helper.
: >
: > Does anyone know of another location where these methods can be
: > accessed by both? Thereby avoiding the duplication of code.
: >
: > Thanks,
: >
: > .k
: >
: >
:
:


konsu

1/27/2006 5:35:00 PM

0

well, i think documentation for "require" explains where it searches for
files.

as far as i remember the path list is in $! variable. just add to it
whatever you need to include more paths.

konstantin


"isamura" <oop@poo.com> wrote in message
news:drddi6$diu$1@domitilla.aioe.org...
> "konsu" <konsu@hotmail.com> wrote ...
> : Hello,
> :
> : did you try to use the "require" functionality and put your methods in
> to a
> : file and just require it?
> :
> : konstantin
>
> You've reminded me to review Module and Mixins. It seems I should use
> "require" and "include". But I am not sure where to place my new
> module file so that both ApplicationController and ApplicationHelper
> classes can "see" it. Is there a modules load PATH I should know about?
>
> Regards,
>
> .k
>
> :
> : "isamura" <oop@poo.com> wrote in message
> : news:drbpb4$rq2$1@domitilla.aioe.org...
> : >I have several methods that can have potential use in both the
> : > controller and view. Currently there are two copies of each method,
> : > one in the controller and the other in the helper.
> : >
> : > Does anyone know of another location where these methods can be
> : > accessed by both? Thereby avoiding the duplication of code.
> : >
> : > Thanks,
> : >
> : > .k
> : >
> : >
> :
> :
>
>


isamura

1/27/2006 5:51:00 PM

0

A closer look at application_helper.rb show it contains a Module
definition. As this is particular to Rails, I think it is acceptable to
add my code here. Then in application_controller.rb I added the
Include ApplicationHelper statement. Testing show I am able to
access the defined methods, as required.

I also find $: to list the module search paths, but $! seem to return
nil.

Cheers!,

..k

"konsu" <konsu@hotmail.com> wrote ...
: well, i think documentation for "require" explains where it searches for
: files.
:
: as far as i remember the path list is in $! variable. just add to it
: whatever you need to include more paths.
:
: konstantin
:
:
: "isamura" <oop@poo.com> wrote in message
: news:drddi6$diu$1@domitilla.aioe.org...
: > "konsu" <konsu@hotmail.com> wrote ...
: > : Hello,
: > :
: > : did you try to use the "require" functionality and put your methods in
: > to a
: > : file and just require it?
: > :
: > : konstantin
: >
: > You've reminded me to review Module and Mixins. It seems I should use
: > "require" and "include". But I am not sure where to place my new
: > module file so that both ApplicationController and ApplicationHelper
: > classes can "see" it. Is there a modules load PATH I should know about?
: >
: > Regards,
: >
: > .k
: >
: > :
: > : "isamura" <oop@poo.com> wrote in message
: > : news:drbpb4$rq2$1@domitilla.aioe.org...
: > : >I have several methods that can have potential use in both the
: > : > controller and view. Currently there are two copies of each method,
: > : > one in the controller and the other in the helper.
: > : >
: > : > Does anyone know of another location where these methods can be
: > : > accessed by both? Thereby avoiding the duplication of code.
: > : >
: > : > Thanks,
: > : >
: > : > .k
: > : >
: > : >
: > :
: > :
: >
: >
:
:


konsu

1/27/2006 7:00:00 PM

0

if you edit a rails file then upgrading rails sitting under your application
will become less than trivial.

i myself would create my own file and use it.


"isamura" <oop@poo.com> wrote in message
news:drdmlb$lmg$1@domitilla.aioe.org...
>A closer look at application_helper.rb show it contains a Module
> definition. As this is particular to Rails, I think it is acceptable to
> add my code here. Then in application_controller.rb I added the
> Include ApplicationHelper statement. Testing show I am able to
> access the defined methods, as required.