[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

load a path (not a file

Elias Orozco

2/20/2009 7:18:00 AM

Hello guys,

I need to load a path not a file. I am trying this but it is not working

load RAILS_ROOT+"/public/users/#{self.login}/lib/"

Can you guys help me,

Thanks
--
Posted via http://www.ruby-....

3 Answers

Stefano Crocco

2/20/2009 7:27:00 AM

0

Alle Friday 20 February 2009, Elias Orozco ha scritto:
> Hello guys,
>
> I need to load a path not a file. I am trying this but it is not working
>
> load RAILS_ROOT+"/public/users/#{self.login}/lib/"
>
> Can you guys help me,
>
> Thanks

What do you mean by "load a path"? A path isn't a ruby file, so you can't load
it. If you mean "load all ruby files contained in a directory", you can do
something like this:

dir = RAILS_ROOT+"/public/users/#{self.login}/lib/"
Dir.entries(d).each do |f|
load File.join(d, f) if file.match(/\.rb$/)
end

Stefano

Tietew

2/20/2009 8:05:00 AM

0


On Fri, 20 Feb 2009 16:26:33 +0900
In article <200902200829.54268.stefano.crocco@alice.it>
[Re: load a path (not a file)]
Stefano Crocco <stefano.crocco@alice.it> wrote:

> > I need to load a path not a file. I am trying this but it is not working
> >
> > load RAILS_ROOT+"/public/users/#{self.login}/lib/"

It is NOT recommended to put ruby files under Rails "public" directory
because their files can be shown by any web browsers in the world.

> dir = RAILS_ROOT+"/public/users/#{self.login}/lib/"
> Dir.entries(d).each do |f|
> load File.join(d, f) if file.match(/\.rb$/)
> end

Dir.[] or Dir.glob is easier.

Dir.glob("#{RAILS_ROOT}/public/users/#{self.login}/lib/*.rb").each { |f| load(f) }


--
Tietew <tietew@tietew.net>


Elias Orozco

2/20/2009 8:14:00 AM

0

Thanks guys,

That was very helpful and just what I wanted.

I will try to move the files to another folder for security then.

Elías
--
Posted via http://www.ruby-....