What's the best way to add kinks in a Rails plugin?
2 answers
I would recommend adding a separate file (inflections.rb) to your plugins lib. You should be able to load the inflections.rb file from the plugin by adding the following to the top of the plugin Ruby file.
require 'inflections"
Your inflections.rb file should follow the format shown 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
+2
a source to share
UPDATE : For those who have the same problem but are using Rails 5, here is the correct answer.
Do not place the inflections.rb
file in a folder plugin/lib
, but in a folder plugin/config/initializers
.
Then just write your kinks (e.g. cliché / cliché):
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'cliche', 'cliches'
end
0
a source to share