How to use a helper which is not inside app/helpers/



I wish to know it is possible to use a helper which is
not inside the folder ‘app/helpers’, if it is
possbile, what should I do?

Thanks you very much!!!


Yahoo! DSL ? Something to write home about.
Just $16.99/mo. or less.


Edit config/environment.rb:

Uncomment config.load_path and add the path that contains your helper.
E.g., if your helper is in dir src/rails/helpers and your rails app is
called plan and is located in src/plan, add this to environment.rb:

config.load_paths += %W( #{RAILS_ROOT}/extras
#{RAILS_ROOT}/…/rails/helpers )

Create a file in src/rails/helpers called (for example)

module FormattingHelper

def format_time(time, format_str = “%m/%d/%Y
%I:%M:%S %p”)

Now in your controller add

helper :formatting

In your views you can access format_time. E.g.:

Started on: <%= format_time @task.created_at %>

Hope this helps.

Stephen V.



thanks you very much for the information, however, I
have tried the cmd “config.load_path”, but it doesn’t
work, I have felling that rails doesn’t not recognized
the path that I added.

actually, the extra helper modules is outside of the
application rails file structure. (I’m using linux)

the extra helpers is stored at /opt/web/extra/helpers/
so I added the following line at the

config.load_paths += %W("/opt/web/extra/helpers/")
and in my controller I added

helper :extra (which the module name is extraHelper,
and the filename is extra_helper.rb)

rails seems to ignore that. when I try to shoe the
webpage, I got error that rails is not able to locate
the extra_helper in /app/helpers/

How can I tell rails that it should look in
/opt/web/extra/helpers/ instead of /app/helpers/?

Thanks you very much


— Stephen V. removed_email_address@domain.invalid wrote:


Started on: <%= format_time @task.created_at which is > __________________________________________ > _______________________________________________ Rails mailing list removed_email_address@domain.invalid

Yahoo! DSL ? Something to write home about.
Just $16.99/mo. or less.