gpt4 book ai didi

ruby-on-rails-3 - Rails 3.2 使用 content_tag 生成带有 twitter-bootstrap 图标的 'Delete' 按钮

转载 作者:行者123 更新时间:2023-12-04 07:09:37 25 4
gpt4 key购买 nike

我正在尝试使用 Rails 3 content_tag 方法复制此示例中的删除按钮图标,在嵌套表单中并使用 jQuery 不显眼(或者至少我希望如此)。
Twitter-Bootstrap Delete Button icon (example)
使用 Firebug 检查时生成的 html 如下。

<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
我正在使用以下内容生成带有图标的按钮,但无法向其中添加“删除成分”,也无法获得 href 的“#”。
这是我在部分成分中的代码:
<%= link_to content_tag(:a, content_tag(:i, '', class: "icon-trash icon-white"), class: "btn btn-danger remove_fields") %>
这会产生:
<a class="btn btn-danger remove_fields">
<i class=icon-trash icon-white"></i>
</a>
这是基于来自
Api dock - content_tag
其中有以下代码示例:
content_tag(:div, content_tag(:p, "Hello world!"), :class => "strong")
# => <div class="strong"><p>Hello world!</p></div>
有人可以指出我正确的方向吗?为什么我错过了上面提到的细节?
注:我可以让它与 link_to block 一起工作,但想知道这是否可以在没有 do..end 的情况下在一行中完成,更重要的是在 content_for 方法中。
<%= link_to('#', class: "btn btn-danger remove_fields") do %>
<i class: "icon-trash icon-white"></i>
Delete
<% end %>

最佳答案

<%= link_to(body, url, html_options = {}) %>

因此,您在 1 行中的请求是:
<%= link_to content_tag(:i, "", class: "icon-trash icon-white") + "Delete", path_to_stuff, method: :delete, class: "btn btn-danger remove_fields" %>

最复杂的部分是“ body ”。您只需要记住所有这些 content_tag 帮助器(包括 link_to 和其他)都返回一个字符串。

但是,这很丑陋。而且很长。并且难以维护。因此,您提出的解决方案要好得多。

关于ruby-on-rails-3 - Rails 3.2 使用 content_tag 生成带有 twitter-bootstrap 图标的 'Delete' 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10312922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com