Plugins and the Inflector

Posted by Jeremy Voorhis Fri, 30 Jun 2006 07:18:21 GMT

This is just a quick warning to anybody who may be using custom rules with the Rails inflector.

In a personal project I am tooling around with, I define the following custom rule for the inflector:


Inflector.inflections do |inflect|
  inflect.uncountable 'trash'
end

but a named route defined by the simply_restful plugin gets the helper trashes_url. Of course, this makes perfect sense – by the time your app is loading your custom inflections, your plugins are already available to be used. simply_restful had pluralized my uncountable word and defined my named routes before I ever had a chance to object.

The interesting question here is which behavior is correct?

Comments

  1. Richard Livsey said about 5 hours later:

    My first thoughts on this is that the custom inflections should be loaded before plugins.

    If a plugin wants do anything involving the names of models/controllers/associations then surely they need to follow the rules you use in the rest of the app, for consistencies sake.

    Is there ever a case when you need plugins to be loaded before you mess with the inflections?

    Then again, it is 8:30am and I’ve not gone to bed yet so odds are there’s another side to this I’m not thinking about now!

  2. JV said 1 day later:

    The edge case is where a plugin includes its own models and database tables, it may expect a certain pluralization rule.

    As the only plugins I can currently think of that include their own models and tables have very straightforward requirements – i.e. acts as taggable, globalize – or derive their names from existing models – acts as versioned – this may be a moot issue and loading the application’s inflections first would be the pragmatic thing to do.

(leave url/email »)