我使用这个命令:在rails中更改生成模型的复数形式?
rails generate model DayOfMonth day:integer
Rails的生成模型 “DAYOFMONTH” 并表 “day_of_months”。
我希望它创建表“days_of_month”,而不是。
我知道这与初始化文件夹中的Inflector类和inflector.rb有关。
但我不明白如何让这个工作。
我用Rails 3
有人能帮助我在这里或点我为这个教程?
感谢
我使用这个命令:在rails中更改生成模型的复数形式?
rails generate model DayOfMonth day:integer
Rails的生成模型 “DAYOFMONTH” 并表 “day_of_months”。
我希望它创建表“days_of_month”,而不是。
我知道这与初始化文件夹中的Inflector类和inflector.rb有关。
但我不明白如何让这个工作。
我用Rails 3
有人能帮助我在这里或点我为这个教程?
感谢
你可以只编辑迁移,然后添加
的Rails 3.2+/4+
class DayOfMonth < ActiveRecord::Base
self.table_name = "days_of_month"
end
的Rails 3
class DayOfMonth < ActiveRecord::Base
set_table_name "days_of_month"
end
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'day of month', 'days of month'
end
阅读:http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
它仍然不起作用。我添加了该行,然后运行“rails generate model DayOfMonth day:integer”,但它仍创建一个名为CreateDayOfMonths的迁移。 – 2010-07-31 15:01:48
你必须说什么在一个初始化“是inflections.rb”“月的一天”的复数形式:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'day of month', 'days of month'
inflect.irregular 'day_of_month', 'days_of_month'
end
为我工作。虽然,在定义与该型号的关联时,我仍然遇到错误:
has_many :days_of_month
这对我有用。看起来有一个可能导致你的问题的轨道错误,但它现在已经修复。 https://github.com/arthurnn/rails/commit/c0b6e164ee6bbc7941d280ea629d70d400561668 – 2014-12-07 05:41:54
此语法现在已更改为'self.table_name =“days_of_month”' – 8bithero 2013-02-28 20:54:30