Question

I have a module I want to call OAuth and a class inside it called AccessToken. Normally in rails I would want to put it in app/models/o_auth/access_token.rb. How can I get it to load from the path app/models/oauth/access_token.rb?

Was it helpful?

Solution 3

I think my question was too subtle. I was asking how to load my class from that specific path, not how to add a path to the autoload path in general. My issue was that because my OAuth class starts with two capital letters, rails expects a path of o_auth as does anything where you might reference it as a symbol. Because of all the overriding you would have to do to get symbol references of oauth to point to an OAuth class, it seems it is better to just name the folder o_auth instead of oauth.

OTHER TIPS

Add a require 'app/models/o_auth/access_token' at the top of application.rb, and at the top of any other model that uses it. This is what you'd have to do for every model, without RoR's "convention over configuration" ideal, and its magic importer.

Add these lines to config/application.rb

# Load Subfolder Models
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top