Skip to content

Instantly share code, notes, and snippets.

@billspat
Created June 5, 2013 17:56
Show Gist options
  • Save billspat/5715831 to your computer and use it in GitHub Desktop.
Save billspat/5715831 to your computer and use it in GitHub Desktop.
Rails view helpers for bootstrap links and buttons with icons
# bootstrap button helpers, iconified
# known to work with gem "bootstrap-sass", ">= 2.3.0.0"
def iconified_link_to(icon, body, url, html_options = {})
# not a button, see below
link_to url, html_options do
"#{content_tag(:i, nil, :class => icon.to_s )}  #{body}".html_safe
end
end
def iconified_button_to(icon, body, url, html_options = {})
html_options[:class] = (html_options[:class] || "" ) + ' btn' #add default btn class to other classes
iconified_link_to(icon, body, url, html_options).html_safe
end
def edit_button(url, html_options = {})
iconified_button_to('icon-pencil', "Edit", url, html_options)
end
def delete_button(url, html_options = {})
html_options[:class] = (html_options[:class] || "" ) + ' btn-danger'
html_options[:method] = :delete
html_options[:data] = { :confirm => 'Are you sure?' }
iconified_button_to('icon-trash icon-white', "Delete", url, html_options)
end
def cancel_button(url = nil, html_options = {})
html_options[:class] = (html_options[:class] || "" ) + ' btn-warning'
iconified_button_to('icon-remove icon-white', "Cancel", url || :back , html_options)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment