[Rails] Where to put self-contained Custom Libraries

B

Brian Takita

Hello,

I'm developing a custom library and would like to know where I can and
should put it.

http://wiki.rubyonrails.com/rails/show/UnderstandingWhatFilesGoesWhere
seems to imply that I should place the custom utility library inside
the lib directory.

I will probably reuse this library and have unit tests for this
library, so I would rather have this library packaged.

One option is to make this library a Gem.
What are my other options within rails?
How would placing something into the vendor directory work? Is there a
web page out there that can tell me what to do?

Thank you,
Brian Takita
 
G

Gennady Bystritksy

Brian said:
Hello,

I'm developing a custom library and would like to know where I can and
should put it.

http://wiki.rubyonrails.com/rails/show/UnderstandingWhatFilesGoesWhere
seems to imply that I should place the custom utility library inside
the lib directory.

I will probably reuse this library and have unit tests for this
library, so I would rather have this library packaged.

One option is to make this library a Gem.
What are my other options within rails?
How would placing something into the vendor directory work? Is there a
web page out there that can tell me what to do?

Thank you,
Brian Takita
You can install it in good old
<ruby installation top>/lib/ruby/site_ruby/1.8, however a Gem sould be a
much better option.

Gennady.
 
J

John W. Long

Brian said:
Hello,

I'm developing a custom library and would like to know where I can and
should put it.

I think the Rails Way would be to put them in the vendor directory or
make them available as a gem. Should you choose to put them in the
vendor directory, you will need to modify your load path in
environment.rb to include the path to your lib. For example, if my lib
was in:

/vendor/mylib/lib

I would want to add that path to the load path in environment.rb:

$LOAD_PATH.unshift(File.join(RAILS_ROOT, 'vendor/mylib/lib'))
 

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
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top