Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Helper for generating the <title> tag

#2657

I don't know about you, but I'm pretty tired of always having to add a helper for generating the "title" tag to my Rails applications. Of course, this could easily be turned into a plugin, but such a small piece of functionality that is so common and essential should really be in the core.

Therefore, I put together a patch that adds a TitleHelper module to ActionView::Helpers containing just a single method called "title". Here is an example:

# Setting the title. For use in <h1> tags, e.g.
title('Welcome')
# => Welcome

title(:site => 'Site')
# => <title>Site - Welcome</title>

Two other options are available:

  • separator for defining the separator between site name and title. Default is " - ".
  • reverse for reversing the order of site name and title. Default is false, site name first.

Alternatively, the helper could be merged into one of the existing helper modules, e.g. the TagHelper module. Test coverage and documentation should be fine.

Ideas are always welcome. :)

Reported by David Knorr · May 16th, 2009 @ 04:32 PM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. David Knorr
  2. Pratik
    Pratik
    • Title changed from [Patch] Helper for generating the <title> tag to Helper for generating the <title> tag

    May 17th, 2009 @ 01:34 PM

  3. Pratik
    Pratik
    • State changed from new to wontfix

    Not sure if I'd use this helper for setting title. People typically use http://railscasts.com/episodes/30-pretty-page-title for setting title. Probably you should ask in the core mailing list and see if more people find this useful. In which case, we can reevaluate the patch.

    Thanks.

    May 17th, 2009 @ 01:39 PM