Question

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

Was it helpful?

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

OTHER TIPS

UPDATE: for anyone who is having the same issue but uses Rails 5, here is the right answer.

Don't place inflections.rb file in plugin/lib folder, but in plugin/config/initializers folder.

Then simply write your inflections (eg cliche/cliches):

ActiveSupport::Inflector.inflections do |inflect|
    inflect.irregular 'cliche', 'cliches'
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top