DRY up gardens and plantings helper

This commit is contained in:
Brenda Wallace
2017-02-07 22:33:48 +13:00
committed by Shiny
parent e6254da3f1
commit ba1c40702b
3 changed files with 13 additions and 12 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)