我使用這個命令:在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