Rails 1.0 methods in application controller vs. helper

I

isamura

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
 
K

konsu

Hello,

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

konstantin
 
I

isamura

: 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

:
: : >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
: >
: >
:
:
 
K

konsu

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
 
I

isamura

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

: 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
:
:
: : > : 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
: >
: > :
: > : : > : >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
: > : >
: > : >
: > :
: > :
: >
: >
:
:
 
K

konsu

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
sxarexu

Latest Threads

Top