Ruby on Rails
UnderstandingHelpers (Version #7)

Introduction

Helpers (“view helpers”) are modules that provide methods which are automatically usable in your view. They provide shortcuts to commonly used display code and a way for you to keep the programming out of your views. The purpose of a helper is to simplify the view. It’s best if the view file (RHTML/RXML) is short and sweet, so you can see the structure of the output. Nitty-gritty details are best left to helper methods and partials, where they can be parametrized and used repeatedly.

Write your own

Rails comes packed with many helpers, but you can also write your own. See HowtoWorkWithHelpers for a walkthrough of writing your own helper method.

Use a contributed helper

See 3rdPartyHelpers for a list of helpers others have written.

Howtos relating to specific helpers

API Reference Documentation

  • ActiveRecordHelper—\ActiveRecord error messages, form, etc.
  • AssetTagHelper—methods for linking an HTML page together with other assets, such as javascripts, stylesheets, and feeds
  • CacheHelper—See ActionController::Caching::Fragments for usage instructions.
  • CaptureHelper—Capture lets you extract parts of code into instance variables which can be used in other points of the template or even layout file.
  • DateHelper—creates select/option tags for different kinds of dates and date elements.
  • DebugHelperdebug
  • FormHelper—methods for working with forms and especially forms related to objects assigned to the template.
  • FormOptionsHelper—methods for turning different kinds of containers into a set of option tags.
  • FormTagHelper—Provides a number of methods for creating form tags that doesn’t rely on an object assigned to the template like \FormHelper does.
  • JavaScriptHelper—helpers for calling Javascript functions and, most importantly, to call remote methods using what has been labelled Ajax.
  • PaginationHelper—methods for linking to Pagination objects.
  • TagHelper—This is poor man’s Builder
  • TextHelper—methods for working with text strings
  • UrlHelper—methods for making easy links and getting urls that depend on the controller and action

category: Understanding

Introduction

Helpers (“view helpers”) are modules that provide methods which are automatically usable in your view. They provide shortcuts to commonly used display code and a way for you to keep the programming out of your views. The purpose of a helper is to simplify the view. It’s best if the view file (RHTML/RXML) is short and sweet, so you can see the structure of the output. Nitty-gritty details are best left to helper methods and partials, where they can be parametrized and used repeatedly.

Write your own

Rails comes packed with many helpers, but you can also write your own. See HowtoWorkWithHelpers for a walkthrough of writing your own helper method.

Use a contributed helper

See 3rdPartyHelpers for a list of helpers others have written.

Howtos relating to specific helpers

API Reference Documentation

  • ActiveRecordHelper—\ActiveRecord error messages, form, etc.
  • AssetTagHelper—methods for linking an HTML page together with other assets, such as javascripts, stylesheets, and feeds
  • CacheHelper—See ActionController::Caching::Fragments for usage instructions.
  • CaptureHelper—Capture lets you extract parts of code into instance variables which can be used in other points of the template or even layout file.
  • DateHelper—creates select/option tags for different kinds of dates and date elements.
  • DebugHelperdebug
  • FormHelper—methods for working with forms and especially forms related to objects assigned to the template.
  • FormOptionsHelper—methods for turning different kinds of containers into a set of option tags.
  • FormTagHelper—Provides a number of methods for creating form tags that doesn’t rely on an object assigned to the template like \FormHelper does.
  • JavaScriptHelper—helpers for calling Javascript functions and, most importantly, to call remote methods using what has been labelled Ajax.
  • PaginationHelper—methods for linking to Pagination objects.
  • TagHelper—This is poor man’s Builder
  • TextHelper—methods for working with text strings
  • UrlHelper—methods for making easy links and getting urls that depend on the controller and action

category: Understanding