简体   繁体   English

Rails嵌套的HTML帮助器

[英]Rails nested html helper

I'm creating a helper in my rails app where I create a navigation link. 我正在我的Rails应用程序中创建一个助手,在其中创建导航链接。 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: 我的html应该看起来像这样:

<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! 谢谢!

You're passing a block to link_to so you shouldn't pass it link text, as shown in the docs . 您正在将一个块传递给link_to因此您不应传递它的链接文本,如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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM