Posted about 1 month ago. Visible to the public. Repeats.

Rails: Passing array values to tag helpers like link_to

From at least Rails 4, the ActionView tag helper turns Array values of HTML options into a single space-separated string.
This means you can pass an array to :class options:

Copy
extra_classes = %w[one two] = link_to 'Dashboard', root_path, class: ['btn', 'btn-primary', *extra_classes] => <a href="/" class="btn btn-primary one two">Dashboad</a> = content_tag 'div', 'Hello World', class: %w[alert alert-info] => <div class="alert alert-info">Hello World</div> = content_tag 'span', 'Hello World', class: [] => <span class>Hello World</span>

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
about 1 month ago
by Besprechungs-PC
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more