From 22e50aa61823cb2d68e12747e6aee37ac9ac98c3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 22 Jan 2019 17:20:34 +1300 Subject: [PATCH] DRY the edit buttons --- app/helpers/buttons_helper.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/helpers/buttons_helper.rb b/app/helpers/buttons_helper.rb index c1121a04f..206322dab 100644 --- a/app/helpers/buttons_helper.rb +++ b/app/helpers/buttons_helper.rb @@ -2,18 +2,10 @@ module ButtonsHelper def seed_add_photo_button(seed) button(new_photo_path(id: seed.id, type: "seed"), 'buttons.add_a_photo', 'camera') end - - def seed_edit_button(seed) - button(edit_seed_path(seed), 'buttons.edit', 'pencil') - end def harvest_add_photo_button(harvest) button(new_photo_path(id: harvest.id, type: "harvest"), 'buttons.add_a_photo', 'camera') end - - def harvest_edit_button(harvest) - button(edit_harvest_path(harvest), 'buttons.edit', 'pencil') - end def garden_plant_something_button(garden) button(new_planting_path(garden_id: garden.id), 'buttons.plant_something_here', 'leaf') @@ -35,13 +27,21 @@ module ButtonsHelper def garden_add_photo_button(garden) button(new_photo_path(id: garden.id, type: "garden"), 'buttons.add_a_photo', 'camera') end + + def seed_edit_button(seed) + edit_button(edit_seed_path(seed)) + end + + def harvest_edit_button(harvest) + edit_button(edit_harvest_path(harvest)) + end def garden_edit_button(garden) - button(edit_garden_path(garden), 'buttons.edit', 'pencil') + edit_button(edit_garden_path(garden)) end def planting_edit_button(planting) - button(edit_planting_path(planting), 'buttons.edit', 'pencil') + edit_button(edit_planting_path(planting)) end def planting_add_photo_button(planting) @@ -68,6 +68,10 @@ module ButtonsHelper button(new_planting_seed_path(planting), 'buttons.save_seeds', 'heart') if can?(:edit, planting) end + def edit_button(path) + button(path, 'buttons.edit', 'pencil') + end + def delete_button(model, message: 'are_you_sure') link_to model, method: :delete, data: { confirm: t(message) }, class: 'btn btn-default btn-xs' do render 'shared/glyphicon', icon: 'trash', title: 'buttons.delete'