在 rails 中更改生成模型的复数形式? [英] Change plural form of generated model in rails?
本文介绍了在 rails 中更改生成模型的复数形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个命令:
rails generate model DayOfMonth day:integer
Rails 生成了模型DayOfMonth"和表day_of_months".
Rails generated the model "DayOfMonth" and the table "day_of_months".
我希望它改为创建表days_of_month".
I want it to create the table "days_of_month" instead.
我知道这与 Inflector 类和 initializers 文件夹中的 inflector.rb 有关.
I know this has something to do with the Inflector class and the inflector.rb in initializers folder.
但我不明白如何让它发挥作用.
But I don't understand how to get this to work.
我使用的是 Rails 3.
I'm using Rails 3.
有人可以帮我解决这个问题或给我指点这方面的教程吗?
Could someone help me out here or point me to a tutorial for this?
谢谢
推荐答案
您可以只编辑迁移然后添加
You could just edit the migration and then add
Rails 3.2+/4+
Rails 3.2+ / 4+
class DayOfMonth < ActiveRecord::Base
self.table_name = "days_of_month"
end
轨道 3
class DayOfMonth < ActiveRecord::Base
set_table_name "days_of_month"
end
这篇关于在 rails 中更改生成模型的复数形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文