开发者

rails using file in lib folder - rails 2.3.5

开发者 https://www.devze.com 2023-03-10 12:38 出处:网络
Normally I put files in the rails lib folder and they seem to be loaded automatically. I recently tried putting this file : https://gist.github.com/85632 in my lib folder.

Normally I put files in the rails lib folder and they seem to be loaded automatically.

I recently tried putting this file : https://gist.github.com/85632 in my lib folder.

From one of my models when I try to do:

 ftp = Net::FTPS::Implicit::new(

I get:

NameError: uninitialized constant Net::FTPS
    from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:开发者_JAVA百科in `load_missing_constant'
    from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
    from /Users/jnylund/Projects/aras/app/models/notifier.rb:372:in `send_ftp_file'

I got it to work by adding: require 'ftps_implicit'

to the top of my model file.

Why in this case did I need to do this? Is this the right way of doing things?

thanks Joel


Rails 2 will load up files by convention. So when you request:

Net::FTPS::Implicit::new

... it will look for the file:

lib/net/ftps/implicit

... to define that class.

I don't think Rails 2 actually loads everything up in the lib folder - it only looks in there for a file when something is requested.


Rails 3 does not load the ./lib directory automatically anymore. If you want to reactivate this behavior in Rails 3 Add the line below to your application config:

config.autoload_paths += %W(#{config.root}/lib)

This is also a repost of this question here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号