Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 CakePHP 中,我可以在我的数据库配置中指定一个前缀,即“so_”,这样每个模型都会在这个前缀下查找它的表。
在 Rails 中也有类似的可能吗?也就是说,多个程序可以共享一个数据库吗?
您可以尝试以下environments.rb操作:在配置部分添加以下代码
environments.rb
config.active_record.table_name_prefix = "so_"
您可以使用 set_table_name 方法轻松地为每个模型指定自己的表名:
class Mouse < ActiveRecord::Base set_table_name "so_mice" end
但是您必须为每个模型都这样做,我不知道任何全局配置选项。