This project is archived and is in readonly mode.

#1780 ✓wontfix
Chris Kalafarski


Reported by Chris Kalafarski | January 19th, 2009 @ 02:02 AM | in 2.x

TagHelper to allows the options of a content_tag to switch based on a provided condition. This is useful when generating groups of tags or when needing a tag to react to a current condition, such as current_controller or a session variable.

content_tag_if(true, :p, 'Hello world!', :class => ['when-true', 'when-false'])
# => <p class="when-true">Hello world!</p>
content_tag_if(false, :p, 'Hello world!', :class => { :if => 'when-true', :else => 'when-false' })
# => <p class="when-false">Hello world!</p>
content_tag_if(current_page?(:controller => 'books'), :p, 'Books', :class => ['current', 'inactive'])
content_tag_if(current_page?(:controller => 'newspapers'), :p, 'Newspapers', :class => ['current', 'inactive'])
# => <p class="current">Books</p><p class="inactive"> Newspapers</p>

ps. This could also be called something like content_tag_with_binary_options, or content_tag_with_options_if.

Comments and changes to this ticket

  • Pascal Ehlert

    Pascal Ehlert January 27th, 2009 @ 09:59 PM

    Waaay to specific to go into core. If you think someone else could use this, creating a plugin will be fairly simple.

    No offense, but strong -1 on this.

  • Chris Kalafarski

    Chris Kalafarski January 27th, 2009 @ 10:21 PM

    to me this functionality seems as specific as link_to_if

  • DHH

    DHH February 5th, 2009 @ 08:02 PM

    • State changed from “new” to “wontfix”

    link_to_if was also a bad idea for core, imo. It should go into a plugin as well.

  • af001

    af001 May 5th, 2011 @ 03:00 AM


Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket