Forum: Ruby on Rails how to use a helper which is not inside app/helpers/

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
14b7344777a56ac9a1fad849f5d6da2a?d=identicon&s=25 Saiho Yuen (Guest)
on 2006-01-05 17:44
(Received via mailing list)
Hi,

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!!!!

Saiho




__________________________________________
Yahoo! DSL ? Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com
E9799593a0bbdefeb9b9651bae9b9c4d?d=identicon&s=25 Stephen Veit (Guest)
on 2006-01-05 19:57
(Received via mailing list)
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)
formatting_helper.rb:

module FormattingHelper

  def format_time(time, format_str = "%m/%d/%Y<br />%I:%M:%S %p")
    time.strftime(format_str)
  end
end


Now in your controller add

  helper :formatting


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

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

Hope this helps.

Stephen Veit
14b7344777a56ac9a1fad849f5d6da2a?d=identicon&s=25 Saiho Yuen (Guest)
on 2006-01-05 21:21
(Received via mailing list)
Hi,

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/environment.rb

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

Saiho




--- Stephen Veit <srveit@gmail.com> wrote:

>
>   end
> <p>Started on: <%= format_time @task.created_at
> which is
> > __________________________________________
> > _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>




__________________________________________
Yahoo! DSL ? Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com
This topic is locked and can not be replied to.