Ruby on Rails: How do you explicitly define plural names and singular names in Rails?

后端 未结 3 1779
故里飘歌
故里飘歌 2020-12-04 21:00

For example, I\'m using \"Bonus\" as my model, so I\'d expect \"bonuses\" to be the plural form and \"bonus\" to be the singular form.

However, in Ruby, this results

相关标签:
3条回答
  • 2020-12-04 21:37

    I believe you use the Inflector in your environment.rb (memory's a bit sketchy though) If I remember correctly you put it in a block

    Inflector.inflections { | i | i.irregular 'bonus', 'bonuses' }
    
    0 讨论(0)
  • 2020-12-04 21:43

    In config/initializers, you will find a file called inflections.rb. There are some instructions in here, but you will want something along the lines of:

    ActiveSupport::Inflector.inflections do |inflect|
      inflect.irregular 'bonus', 'bonuses'
    end
    
    0 讨论(0)
  • 2020-12-04 21:50

    Just to back up bcarlso, more on Inflector can be found here:

    http://4loc.wordpress.com/2009/04/09/inflector-rails-pluralization/

    Note that the position of the Inflector.inflections block is important and, as noted in the link reference, must be after the Initializer.run block.

    0 讨论(0)
提交回复
热议问题