我想在提交标记中复制此内容:
<%= link_to "<i class='icon-shopping-cart icon-large'></i> Checkout (#{number_to_currency(@item.price, precision: 0)})".html_safe, @item.link.url, class: "btn btn-success btn-large"%>
所以我尝试了这个:
<%= submit_tag "<i class='icon-shopping-cart icon-large'></i> Checkout (#{number_to_currency(@item.price, precision: 0)})".html_safe, :id => "submit", class: "btn btn-success btn-large" %>
但那没用。它只是给了我一个巨大的屁股按钮,在提交文本中有一些HTML。
如何逃避HTML?
修改1
以下是submit_tag
生成的HTML:
<input class="btn btn-success btn-large" id="submit" name="commit" type="submit" value="<i class='icon-shopping-cart icon-large'></i> Checkout ($7)">
答案 0 :(得分:1)
提交按钮不能包含任何嵌入式html,因此最好的选择是:
<button type="submit" class="btn btn-success btn-large" id="submit">
<i class='icon-shopping-cart icon-large'></i> Checkout <%= number_to_currency(@item.price, precision: 0) %>
</button>
答案 1 :(得分:1)
尝试使用button_tag
,我没有测试过,但它接受了一个块:
button_tag(type: 'submit', class: "btn btn-success btn-large") do
"<i class='icon-shopping-cart icon-large'></i> Checkout (#{number_to_currency(@item.price, precision: 0)})".html_safe
end
中搜索“button_tag”
希望这有帮助!