Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Duane Johnson http://blog.inquirylabs.com/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

content_tag that accepts a block = block_tag

Sometimes I want to do something like this:

<% content_tag("div", :class => "section_with_error" do %>
  HTML GOES HERE
<% end %>


instead of this:

<%= content_tag("div", "HTML GOES HERE", :class => "section_with_error") %>


Put the following code in ApplicationHelper, and you can do just that (replacing "content_tag" in the example above with "block_tag", of course):

  def block_tag(tag, options = {}, &block)
    concat(content_tag(tag, capture(&block), options), block.binding)
  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS