From 06ae5ecd6fae8cf010809f2909258fe1a018dba6 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 26 Jun 2019 09:12:39 +1200 Subject: [PATCH] DRY buttons --- app/helpers/buttons_helper.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/helpers/buttons_helper.rb b/app/helpers/buttons_helper.rb index 685cb2438..cbcab26a3 100644 --- a/app/helpers/buttons_helper.rb +++ b/app/helpers/buttons_helper.rb @@ -30,18 +30,22 @@ module ButtonsHelper end def crop_plant_button(crop) - return unless can? :create, Planting - - link_to new_planting_path(params: { crop_id: crop.id }), class: 'btn btn-sm' do - planting_icon + ' ' + t('buttons.plant') - end + create_button(Planting, + new_planting_path(params: { crop_id: crop.id }), + planting_icon, t('buttons.plant')) end def crop_save_seeds_button(crop) - return unless can?(:create, Seed) + create_button(Seed, + new_seed_path(params: { crop_id: crop.id }), + seed_icon, t('buttons.save_seeds')) + end - link_to new_seed_path(params: { crop_id: crop.id }), class: "btn btn-sm" do - seed_icon + ' ' + t('buttons.save_seeds') + def create_button(model_to_create, path, icon, label) + return unless can?(:create, model_to_create) + + link_to path, class: "btn btn-sm" do + icon + ' ' + label end end