Niels
Niels

Reputation: 609

Rails nested html helper

I'm creating a helper in my rails app where I create a navigation link. Now I want to add an caret to this link so I can get a nice arrow at the end.

My html should look like this:

<li class='dropdown'>
   <a class='dropdown-toggle' data-toggle='dropdown' href='#'
       Dropdown
       <b class='caret'></b>
   </a>

Now I got my helpers setup like this:

  content_tag(:li, class: 'active dropdown') do
    link_to( text, link, class: 'dropdown-toggle' ) do
      content_tag(:b, class: 'caret')
    end
  end

But when I do this I got this error message:

undefined method `stringify_keys' for "/":String

I also want to add some item to my dropdown so I need to nested some more but I don't know how. Is there anybody who could help me and point me in the right direction?

Thanks!

Upvotes: 0

Views: 673

Answers (1)

Buck Doyle
Buck Doyle

Reputation: 6397

You’re passing a block to link_to so you shouldn’t pass it link text, as shown in the docs. Try this:

content_tag(:li, class: 'active dropdown') do
  link_to(link, class: 'dropdown-toggle' ) do
    "#{text}#{content_tag(:b, "", class: 'caret')}".html_safe
  end
end

Upvotes: 3

Related Questions