0

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!

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Almost there but now it escapes the html for the caret, I already tried some combination with html_safe but without the right result. Any other suggestions ?
Oh yes. content_tag needs the tag content as its second parameter if there’s no block, so I added an empty string. As an aside, have you considered using an :after CSS selector to attach your arrow?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.