我有这段代码:
# app/models/ta.rb
module Ta
def self.table_name_prefix
'ta_'
end
end
...
# app/models/ta/article.rb
module Ta
class Article < ActiveRecord::Base
end
end
从rails控制台......
# development environment
Loading development environment (Rails 4.1.6)
2.1.3 :001 > Ta::Article.table_name
=> "ta_articles"
2.1.3 :002 >
...
# production environment
Loading production environment (Rails 4.1.6)
2.1.3 :001 > Ta::Article.table_name
=> "articles"
2.1.3 :002 >
为什么会这样?
答案 0 :(得分:1)
添加到config/initializers/namespace.rb
之类的内容:
require Rails.root.join('app', 'models', 'ta')
应该解决你的问题。