From ba1c40702bc3c195f569b9cd53d88d260eb4d97a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 7 Feb 2017 22:33:48 +1300 Subject: [PATCH] DRY up gardens and plantings helper --- app/helpers/application_helper.rb | 11 +++++++++++ app/helpers/gardens_helper.rb | 7 +------ app/helpers/plantings_helper.rb | 7 +------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 447daa19e..7f5b6d9ea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -81,4 +81,15 @@ module ApplicationHelper model_name = model.model_name.human(count: size) "#{size} #{model_name}" end + + def show_inactive_tickbox_path(type, owner, show_all) + all = show_all ? '' : 1 + if owner + plantings_by_owner_path(owner: owner.slug, all: all) if type == 'plantings' + gardens_by_owner_path(owner: owner.slug, all: all) if type == 'gardens' + else + plantings_path(all: all) if type == 'plantings' + gardens_path(all: all) if type == 'gardens' + end + end end diff --git a/app/helpers/gardens_helper.rb b/app/helpers/gardens_helper.rb index b4f4ffec2..41d7c3c0a 100644 --- a/app/helpers/gardens_helper.rb +++ b/app/helpers/gardens_helper.rb @@ -10,12 +10,7 @@ module GardensHelper end def gardens_active_tickbox_path(owner, show_all) - all = show_all ? '' : 1 - if owner - gardens_by_owner_path(owner: owner.slug, all: all) - else - gardens_path(all: all) - end + show_inactive_tickbox_path('gardens', owner, show_all) end def display_garden_name(garden) diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index 2376039ce..fc837df0a 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -42,12 +42,7 @@ module PlantingsHelper end def plantings_active_tickbox_path(owner, show_all) - all = show_all ? '' : 1 - if owner - plantings_by_owner_path(owner: owner.slug, all: all) - else - plantings_path(all: all) - end + show_inactive_tickbox_path('plantings', owner, show_all) end def plantings_title(owner, crop)