Rails 和引导程序 - 将 HTML 标签添加到提交按钮文本 [英] Rails and bootstrap - Add HTML tags to a submit button text

查看:20
本文介绍了Rails 和引导程序 - 将 HTML 标签添加到提交按钮文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ajax 的喜欢/不喜欢按钮的表单:

I have a form for a like/unlike button using ajax :

= form_for like, :html => { :method => :delete}, :remote => true do |f|
= f.submit pluralize(@video.likes.count, 'like'), :class => "btn btn-warning btn-mini", "data-disable-with"=> "Just a moment..."

表单完美运行.

我想在提交按钮的文本前添加一个图标.添加图标的haml代码如下(twitter bootstrap):

I would like to add an icon in front of the text in the submit button. The haml code for adding the icon is the following (twitter bootstrap) :

%i.icon-heart.icon-white

有没有办法把这个html添加到按钮上?我尝试将其添加为纯 html,但 Rails 将其呈现为文本.

Is there a way to add this html to the button? I tried adding it as plain html, but rails rendered it as text.

更新

我设法将提交按钮封装在包含图标和适当样式的 span 类中.我现在需要删除按钮上的所有样式...

I have manage to encapsulate the submit button in a span class which contains the icon and the appropriate styling. I now need to remove every styling on the button...

%span.btn.btn-danger.btn-mini
  %i.icon-heart.icon-white
  = f.submit pluralize(@video.likes.count, 'like')

推荐答案

感谢 ismaelga,我找到了 这个问题.

Thanks to ismaelga, I found this SO question.

这是解决方案:

<%= button_tag(type: 'submit', class: "btn btn-primary") do %>
 <i class="icon-ok icon-white"></i> Save
<% end %>

这篇关于Rails 和引导程序 - 将 HTML 标签添加到提交按钮文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆