我的结构类似于(基于this):
# lib/myapp/uploader.rb
require 'uploader/base'
# lib/myapp/uploader/base.rb
module MyApp
module Uploader
class Base
end
end
end
# app/models/model.rb
class Model < ActiveRecord::Base
def test
MyApp::Uploader::Base
end
end
直接在控制台中调用:
$ MyApp::Uploader::Base #> MyApp::Uploader::Base
通过控制台中的模型:
$ Model.new.test
LoadError: Expected <snip>/lib/myapp/uploader.rb to define Uploader
为什么会这样,我该如何解决?
答案 0 :(得分:1)
更新的答案:
在这种情况下,您错过了模型中的要求
请在app/models/model.rb
# app/models/model.rb
class Model < ActiveRecord::Base
require Rails.root.join('lib').join('myapp').join('uploader').join('base').to_s
def test
MyApp::Uploader::Base
end
end