Search code examples
ruby-on-railsrubymodelplural

Ruby on Rails - Define plural name of Model or Table


I have this model

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

basically I have this model and model Interesse and its plural its interesses but I think Rails is actually taking off the es at the end and leaving me with Interess. And now it gives me this error:

uninitialized constant Oferta::Interess

How can I define that the singular to interesses is interesse? and not interess


Solution

  • You can do something like this in your config/initializers/inflections.rb file.

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