7

Rails n00b question. I am creating a plain old Ruby object in Rails. But I am not sure if there is a standard location in the app that I should put this object.

Thanks

1 Answer 1

6

Several choices, but the lib directory is the most common.

If you need to initialize the code, the most common place is config/initializers.

So you might have:

lib/mystuff.rb

and:

config/initializers/mystuff.rb
lib/mystuff.rb

contains your ruby code.

config/initializers/mystuff.rb

contains code that initializes your stuff, whatever Ruby files that are found in config/initializers are run when Rails boots up.

Sign up to request clarification or add additional context in comments.

3 Comments

So to access it would I just add require 'lib/my_object.rb'
Remember that only things in app and config/routes.rb are automatically reloaded between requests. For other things you'll need to restart your server for the changes to take effect.
require 'my_object' should suffice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.