Rails模块self.table_name_prefix不适用于生产环境

时间:2015-09-08 16:18:13

标签: ruby-on-rails ruby-on-rails-4 module production-environment dev-to-production

我有这段代码:

# 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 >

为什么会这样?

1 个答案:

答案 0 :(得分:1)

添加到config/initializers/namespace.rb之类的内容:

require Rails.root.join('app', 'models', 'ta')

应该解决你的问题。