문제

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?

도움이 되었습니까?

해결책 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.

다른 팁

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', '{**}')]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top