Ruby on Rails Tuesday, June 7, 2016

Please do yourself a favor and visit the Rails Guides site: http://guides.rubyonrails.com and read them. All of this is documented well.

To add a data attribute in ERB, you make a nested hash with data as the outermost key:

<%= link_to( nil, data: { data_toggle: 'dropdown' }, role: 'button', 'aria-expanded': 'false' ) do %>
Groups
<span class="caret"></span>
<%- end %>

You didn't ask about aria-expanded, but that's how you would add that as well (Ruby 2.3 syntax, don't try this on 1.9.x). The point of using data as a hash is that you often have many different data-attributes on the same element, so you would do data: { foo: 'bar', baz: 'boo' } and end up with data-foo="bar" data-baz="boo" in the generated HTML.

Walter

> On Jun 7, 2016, at 6:17 PM, Nana Kwame <lists@ruby-forum.com> wrote:
>
> How to create this:
>
>
> <a data-toggle="dropdown" role="button"
> aria-expanded="false">Groups<span class="caret"></span> <a/>
>
> Using link_to method
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/54fd5772eebc2f8f2d02cc6d50110fee%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/A86E5F33-1812-41F9-8FE0-C47EA9D578C9%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment