我正在编写一个需要一些自己的插件的插件。使用导轨2.3,它有引擎嵌入,我应该放置我的变形?

有帮助吗?

解决方案

我建议在插件lib目录插件中添加一个单独的文件(inflections.rb)。您应该能够通过在插件Ruby文件的开头添加以下内容从插件加载inflections.rb文件。

require 'inflections"

您的inflections.rb文件应遵循新Rails项目中提供的格式:

# 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

其他提示

更新:对于遇到相同问题但使用Rails 5的人来说,这是正确答案。

不要将 inflections.rb 文件放在 plugin / lib 文件夹中,而是放在 plugin / config / initializers 文件夹中。

然后简单地写下您的变形(例如陈词滥调/陈词滥调):

ActiveSupport::Inflector.inflections do |inflect|
    inflect.irregular 'cliche', 'cliches'
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top