Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
79

Chapter 3 CHAPTER 3


Rails Plugins 3


Civilization advances by extending the number of
important operations which we can perform
without thinking of them.
—Alfred North Whitehead

Ruby on Rails is very powerful, but it cannot do everything. There are many features
that are too experimental, out of scope of the Rails core, or even blatantly contrary to
the way Rails was designed (it is opinionated software, after all). The core team can-
not and would not include everything that anybody wants in Rails.


Luckily, Rails comes with a very flexible extension system. Rails plugins allow devel-
opers to extend or override nearly any part of the Rails framework, and share these
modifications with others in an encapsulated and reusable manner.


About Plugins


Plugin Loading


By default, plugins are loaded from directories undervendor/pluginsin the Rails
application root. Should you need to change or add to these paths, theplugin_paths
configuration item contains the plugin load paths:


config.plugin_paths += [File.join(RAILS_ROOT, 'vendor', 'other_plugins')]

By default, plugins are loaded in alphabetical order;attachment_fuis loaded before
http_authentication. If the plugins have dependencies on each other, a manual load-
ing order can be specified with theplugins configuration element:


config.plugins = %w(prerequisite_plugin actual_plugin)

Any plugins not specified inconfig.pluginswill not be loaded. However, if the last
plugin specified is the symbol:all, Rails will load all remaining plugins at that point.
Rails accepts either symbols or strings as plugin names here.


config.plugins = [ :prerequisite_plugin, :actual_plugin, :all ]
Free download pdf