load a path (not a file)

E

Elias Orozco

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
 
S

Stefano Crocco

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
 
T

Tietew

On Fri, 20 Feb 2009 16:26:33 +0900
[Re: load a path (not a file)]

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) }
 
E

Elias Orozco

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
 

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

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top