2014-08-28 84 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