Adding a Twitter Bootstrap button icon to button_to in Rails
It looks like you have an issue with your quotes:
<%= button_to raw("<i class=\"icon-search icon-white\">Add To Cart</i>"),
line_items_path(product_id: product),
class: "btn btn-success" %>
Enclose the label of the button in double quotes, escape the double quotes in your i
tag, and finally, wrap everything into a raw()
call to ensure the HTML is properly displayed.Alternatively you can use html_safe
:
<%= button_to "<i class=\"icon-search icon-white\">Add To Cart</i>".html_safe,
line_items_path(product_id: product),
class: "btn btn-success" %>
good point from @jordanpg: you can't have HTML in the value of a button, so his solution is more appropriate and should get the approved status.
the
html_safe
part remains valid though. How can I add bootstrap's icon to button_to in rails3
Try using a block
<%= link_to girl, confirm: 'Are you sure?', disable_with: 'deleting...', method: :delete, class: 'btn-mini btn-danger btn' do %>
<i class="icon-pencil icon-white"></i> Destroy
<% end %>
http://apidock.com/rails/v3.2.1/ActionView/Helpers/UrlHelper/button_tohttp://apidock.com/rails/v3.2.1/ActionView/Helpers/UrlHelper/link_to
Adding a glyph icon in a Rails button
this is what works with button_to
<%= button_to random_joke_path, {remote: true, class: "btn btn-small"} do %>
Następny <i class="icon-play"></i>
<% end %>
Creating a button with a bootstrap icon that can be disabled
I've found then answer is to use a link_to_if block as follows:
<%= link_to_if(department.deletable?, '<i class="icon-remove icon-large"></i>'.html_safe, department_path(department.id), class: 'btn btn-small', disabled: !department.deletable?, method: :delete) {
'<span class="btn btn-small btn-delete disabled"><i class="icon-remove icon-large"></i>'.html_safe
} %>
Block content is only shown if department.deletable? is false Adding a bootstrap glyphicon to a button in rails
<%= button_tag raw("<i class='srch-control-icon-srch'></i> search"), class: "button round" %>
how to add an bootstrap icon to simple_form's link_to_remove_association and link_to_add_association
link_to_add_association
is an user defined helper method. In that method, we have link_to
tag.
Go to your link_to_add_association
method(It may be in your helper), there should be a link_to
tag. For example, In my link_to_add_association
def link_to_add_association(f, association, **args)
###your code goes here
link_to('#', class: "xyx " , data: {id: xyz}) do
"<span class='fa fa-male fa-lg'>".html_safe
end
end
I have used the font-awesome icon. You can use bootstrap icon instead.Reference: link_to
How do you add an icon to a button_tag using HAML?
If you're looking to put an icon inside a button with Bootstrap and HAML, try:
%button.btn.btn-lg.btn-default
%i.glyphicon.glyphicon-play
Using bootstrap icons with button_to delete in rails 3
try this...for example with link
_to
<%= link_to (‘<i class=“fa fa-thumbs-up fa-lg”> </i>’).html_safe, vote_path(@image), :method=> :delete, :remote=> true%>
Related Topics
How to Include Actionmailer Class in Rake Task
Adding Two Activerecord::Relation Objects
How to Share Code Across Chef Cookbooks in a Chef-Repo
How to Use C# Style Enumerations in Ruby
Problem with Vim's Ruby Plugin
Why Can't The Mail Block See My Variable
How to Remove a Url's Trailing Slash in a Rails App? (In a Seo View)
What Is The Ruby Equivalent to This Curl Request
How Does String.Unpack Work in Ruby
In Ruby, Is Truthiness Idiomatic for a Method Name Ending with a Question Mark
Thor Executable - Ignore Task Name
How to Resize Image Only If Width Exceeds with Graphics/Image Magick
Access Rake Task Description from Within Task
How to Handle Serialized Edit Fields in an Active Admin Resource
Rvm Can No Longer Install 1.8.7-P352 on MAC Os X Mountain Lion