ruby-on-railsruby-on-rails-plugins

What is the best way to add inflections in a Rails plugin?


I'm writing a plugin that needs some inflections of it's own. Using rails 2.3 which has the engines imbedded, where I should place my inflections?


Solution

  • I'd recommend adding a separate file (inflections.rb) in your plugins lib directory plugin. You should be able to load the inflections.rb file from the plugin by adding the following at the beginning of the plugin Ruby file.

    require 'inflections"
    

    Your inflections.rb file should follow the format provided as an example in new Rails projects:

    # Sample Inflections    
    # ActiveSupport::Inflector.inflections do |inflect|
    #   inflect.plural /^(ox)$/i, '\1en'
    #   inflect.singular /^(ox)en/i, '\1'
    #   inflect.irregular 'person', 'people'
    #   inflect.uncountable %w( fish sheep )
    # end