如何在Rails3中使用button_to添加Bootstrap图标

4

我的原始代码是

<%= button_to 'Destroy', girl, confirm: 'Are you sure?', :disable_with => 'deleting...', method: :delete, :class => 'btn-mini btn-danger btn'  %>

我希望在“销毁”一词前面添加一个图标。 图标标签如下:
<i class="icon-pencil icon-white"></i>

我该怎么做呢?
1个回答

9

谢谢!我已经将它更改为 <td> <%= button_to 'Destroy', girl, confirm: 'Are you sure?', :disable_with => 'deleting...', method: :delete, :class => 'btn-mini btn-danger btn' do %> <i class="icon-pencil icon-white"></i>销毁 <% end %> </td> 但是还是没有变化... - MKK
在http://twitter.github.com/bootstrap/base-css.html#icons上写着:“当与文本字符串一起使用时,例如按钮或导航链接,请确保在<i>标签后留出空格以获得适当的间距。” - house9
另外,Rails 可能会转义 HTML,如果需要,请将其包装在字符串中并传递给原始函数。 - house9
你需要移除 button_to 的第一个参数,它现在在 block 中。此外,你可能需要使用 link_to,而不是 button_to,我认为它们都支持 block。 - house9

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接