Helperful - A collection of Rails helpers¶
Helperful aims to be a collection of useful and reusable Rails helpers.
Plugin Installation¶
As a Gem¶
This is the preferred way to install Helperful and the best way if you want install a stable version.
$ gem install weppos --source http://gemcutter.org
You can specify the GEM dependency in your application environment.rb file:
1 Rails::Initializer.run do |config|
2 config.gem "helperful", :source => "http://gemcutter.org"
3 end
As a Plugin¶
This is the preferred way if you want to live on the edge and install a development version.
$ script/plugin install git://github.com/weppos/helperful.git
Getting Started¶
Helper methods are grouped into different files according to their scope.
Before using an helper method you should include the helper file in your Rails application, as you would expected to do for a standard Rails helper.
All helpers belongs to the Helperful namespace to prevent conflicts with default Rails helpers. Don't forget to add the namespace when including an helper from your controller.
1 class MyController < ApplicationController
2
3 # include the title_helper
4 helper 'helperful/title'
5
6 # include the title_helper passing the qualified the module name
7 helper Helperful::TitleHelper
8
9 end
Moreover, the Helperful library provides a helpful method called helperful.
It aliases the standard Rails ActionController::Base#helper method with the exception that it automatically prepends the helperful namespace when necessary.
1 class MyController < ApplicationController
2
3 # include the title_helper
4 helperful :title
5
6 # include the title_helper passing the qualified the module name
7 helperful Helperful::TitleHelper
8
9 end
The following lines are equivalent:
1 helper 'helperful/title'
2 helper :'helperful/title'
3 helper Helperful::TitleHelper
4 helperful 'title'
5 helperful :title
6 helperful Helperful::TitleHelper
The helperful methods accepts any parameter accepted by the original helper method.
1 helper 'helperful/title', 'helperful/affiliations'
2 helperful :title, :affiliations
See the Rails documentation for ActionController::Base#helper method for more details about how to include an helper into a Rails application.
Once included, all helper methods are available in the View.
<html>
<title><%= title 'This is a title' %></title>
<body>
<%= yield %>
</body>
</html>
Helpers¶
Here's the list of all available helper modules.
- AffiliationsHelper
- AssetTagHelper (>= 0.4)
- ContentHelper
- JavascriptHelper (>= 0.3)
- TitleHelper
Resources¶
License¶
Copyright (c) 2008-2009 Simone Carletti, Helperful is released under the MIT license.