From 8ee68cecce581cb1f61570fdd9714b8db0207c8e Mon Sep 17 00:00:00 2001 From: Florian Bogenhard Date: Fri, 8 Aug 2014 23:48:07 +0200 Subject: [PATCH] =?UTF-8?q?f=C3=BCgt=20den=20btn=5Flink=5Fto=20helper=20hi?= =?UTF-8?q?nzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..c8932b2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,23 @@ module ApplicationHelper + def btn_link_to(name, path, *args) + options = args.extract_options! + html_class = "btn " + (options.delete(:class) || 'btn-default') + icon = options.delete(:icon) + + if icon + if icon.is_a? Hash + icon_class = icon[:class] + icon = icon[:icon] + end + span = content_tag("span", nil, class: "glyphicon glyphicon-#{icon} #{icon_class}") if icon + + if name && !name.empty? + name = "#{span} #{name}".html_safe + else + name = "#{span}".html_safe + end + end + + link_to name, path, {class: html_class}.update(options) + end end