2014-08-28 56 views
1

的多個名字,我有這個模型Ruby on Rails的 - 定義模式或表

class Oferta < ActiveRecord::Base 
    belongs_to :entidade 
    has_many :candidatos, :through => :interesses 
    has_many :interesses, foreign_key: "oferta_id", dependent: :destroy 

基本上我有這個模型和模型Interesse及其複數其interesses但我認爲Rails的是在實際起飛的es結束並讓我與Interess。現在,它給了我這個錯誤:

uninitialized constant Oferta::Interess 

我如何定義的單數interessesinteresse?而不是interess

+1

請參閱http://stackoverflow.com/questions/1185035/how-do-i-override-rails-naming-conventions – 2014-08-28 08:52:59

+0

有用的鏈接。謝謝! – Lokuzt 2014-08-28 08:58:06

回答

10

你可以在你的config/initializers/inflections.rb文件中這樣做。

ActiveSupport::Inflector.inflections do |inflect| 
inflect.irregular 'interesse', 'interesses' 
end 
+0

是的。我看到上面的鏈接。但是,這就是我所做的。感謝你的回答。我會盡快接受它 – Lokuzt 2014-08-28 08:58:36

+0

請參閱編輯Rails 3.0 + – 2014-08-28 08:59:45

+4

根據上面的鏈接,您的自定義變化應該駐留在'config/initializers/inflections.rb' – Rahul 2014-08-28 09:01:03