Question about lib directory.
What are good practices in using the lib directory?
When should it be used over app/models or app/helpers?
And somewhat related how do you get Rails 3 to include files from the lib directory?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One use of the lib directory (how I use it most often) is to share code between models to stay DRY. For example, if you are defining a
tag_tokensattribute on many different models for use with a tokenizer input, you could put that in “tag_accessor.rb” or something, place it in/lib‘, and then include it withinclude TagAccessor. The ruby file might look like:(This is an example from one of my apps, which is why it’s so specific). Then to load the /lib folder in Rails 3, place this in your
application.rb: