How to add data-some thing with link_to method

The question is how to create this:

Launch Modal

Using link_to method

On Tue, Mar 27, 2012 at 9:16 PM, Karthikeyan A k
[email protected]wrote:

The question is how to create this:

Launch Modal

Using link_to method

<%= link_to “Launch Modal”,"#myModal", :data => {:toggle=>“modal”},
:class=>“btn”%>

Thanks a lot!

  • Link (current</span
  • Link
  • Link (current</span
  • Link
  • Link (current)
  • Link
  • On 6 June 2016 at 14:44, Nana K. [email protected] wrote:

  • Link (current)
  • Link
  • Are you trying to ask a question? If so it is not at all clear what
    the question is. I suggest asking the question in the form of a
    sentence explaining what you are trying to do.

    Colin

    Am trying to rewrite this html (

  • Link
    <span

    class=“sr-only”>(current)

  • Link
  • ) into
    ruby syntax

    Thanx

    The question is how to create this:

  • Link class="sr-only">(current)
  • Link</a
  • )

    Using link_to method

  • Link (current
  • Link
  • On Jun 6, 2016, at 5:04 PM, Nana K. [email protected] wrote:

    Am trying to rewrite this html (

  • Link
    <span

    class=“sr-only”>(current)

  • Link
  • ) into
    ruby syntax

    <%= content_tag :li, class: ‘active’ do %>
    <%= link_to ‘#’ do %>
    Link
    <%= content_tag :span, ‘(current)’, class: ‘sr-only’ %>
    <%- end -%>
    <%- end -%>
    <%= content_tag :li, link_to(‘Link’, ‘#’) %>

    Assuming by ruby you mean ERB syntax…

    Walter

    Thank you

    How to create this:

    Groups

    Using link_to method

    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

    <%- 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

    Sorry, this should read data: { toggle: ‘dropdown’ } – typo on my part.

    Walter

    You can pass a block to #link_to. An example from the docs:

    <%= link_to(@profile) do %>
    <%= @profile.name %>Check it out!
    <% end %>

    =>

       <strong>David</strong> -- <span>Check it out!</span>
     </a>
    

    See
    http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

    Greg Navis
    I help tech companies to scale Heroku-hosted Rails apps.
    Free, biweekly scalability newsletter for SaaS CEOs
    http://www.gregnavis.com/newsletter/

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs