Skip to content

Instantly share code, notes, and snippets.

@justinfrench
Created May 31, 2011 01:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfrench/999715 to your computer and use it in GitHub Desktop.
Save justinfrench/999715 to your computer and use it in GitHub Desktop.
Did you know you can pass classes into Rails tag helpers as Arrays?
# Let's say you've programatically built up an array of classes for a HTML element:
my_classes = [:a, :b, 'c']
# Don't do this, join(" ") is for chumps:
<% content_tag(:p, "Foo", :class => my_classes.join(" ")) %>
# Winners do this:
<% content_tag(:p, "Foo", :class => my_classes) %>
# => <p class="a b c">Foo</p>
<% link_to("Foo", foos_path, :class => my_classes) %>
# => <a href="/foos" class="a b c">Foo</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment