[英]Converting wrapped anchor tag HTML to link_to
I'm messing around with Bootstrap. 我搞不懂Bootstrap。 There's some HTML code which is wrapped by an anchor tag.
有一些HTML代码由定位标记包装。 I'm not really sure how to convert it to the Rails
link_to
method. 我不太确定如何将其转换为Rails
link_to
方法。 I looked at the Ruby on Rails documentation for link_to
but I still cannot figure it out. 我查看了Ruby on Rails文档中的
link_to
但仍然无法弄清楚。
Here's the code: 这是代码:
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
I tried the following but it's incorrect: 我尝试了以下操作,但这是不正确的:
<% link_to("Users", users_path, { data: { toggle: "dropdown" }, class: "dropdown-toggle"} ) do %>
<b class="caret"></b>
<% end %>
If the href is a pure '#" but no variables at all, it's better to copy the code directly from Bootstrap than making a link_to
. 如果href是一个纯粹的'#“但根本没有变量,那么直接从Bootstrap复制代码比制作一个
link_to
更好。
If you want to add variable/method say user_path
, with this complex anchor, it's better to use the block argument of link_to
. 如果要使用此复杂的锚点添加变量/方法,例如
user_path
,最好使用link_to
的block参数。 Move the first argument which is usually the anchor to the block. 移动第一个参数,通常是该块的锚点。
<%= link_to users_path, data: {toggle: "dropdown"}, class: "dropdown-toggle" do %>
<b class="caret"></b>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.