Saiho Yuen
2006-Jan-05 16:07 UTC
[Rails] how to use a helper which is not inside app/helpers/
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
Stephen Veit
2006-Jan-05 16:51 UTC
[Rails] how to use a helper which is not inside app/helpers/
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
On 1/5/06, Saiho Yuen <sayoyo@yahoo.com> wrote:> 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
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Saiho Yuen
2006-Jan-05 20:20 UTC
[Rails] how to use a helper which is not inside app/helpers/
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:
> 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
>
> On 1/5/06, Saiho Yuen <sayoyo@yahoo.com> wrote:
> > 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
> >
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> >
> http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> > _______________________________________________
> 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