From aea0d5877d65782d392ad2b7f5fe07a2467cd57d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 25 Dec 2019 16:23:13 +1300 Subject: [PATCH] use object instead of hash for displaying crops --- app/views/crops/_crop.html.haml | 2 +- app/views/crops/_search_result.haml | 14 -------------- app/views/crops/_thumbnail.html.haml | 9 ++++----- app/views/crops/index.html.haml | 4 ++-- app/views/home/_crops.html.haml | 4 ++-- 5 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 app/views/crops/_search_result.haml diff --git a/app/views/crops/_crop.html.haml b/app/views/crops/_crop.html.haml index 9c763518d..e32a933a3 100644 --- a/app/views/crops/_crop.html.haml +++ b/app/views/crops/_crop.html.haml @@ -6,7 +6,7 @@ crop .card-body %h3.card-title - %strong= link_to crop, crop + %strong= link_to crop.name, crop_path(slug: crop.slug) = crop.default_scientific_name .d-flex.justify-content-between - if crop.annual? && crop.median_lifespan.present? diff --git a/app/views/crops/_search_result.haml b/app/views/crops/_search_result.haml deleted file mode 100644 index 649b1729f..000000000 --- a/app/views/crops/_search_result.haml +++ /dev/null @@ -1,14 +0,0 @@ -.card.crop-thumbnail - = link_to crop_path(slug: crop['slug']) do - - = image_tag(crop['thumbnail_url'] ? crop['thumbnail_url'] : placeholder_image, - alt: crop['name'], - class: 'img img-card') - - .text - %h3.crop-name - = link_to crop['name'], crop_path(slug: crop['slug']) - %h5.crop-sci-name -   - = crop['scientific_name'] - diff --git a/app/views/crops/_thumbnail.html.haml b/app/views/crops/_thumbnail.html.haml index 948c59bbc..29617b768 100644 --- a/app/views/crops/_thumbnail.html.haml +++ b/app/views/crops/_thumbnail.html.haml @@ -1,12 +1,11 @@ - cache crop do .card.crop-thumbnail - = link_to image_tag(crop_image_path(crop), + = link_to image_tag(crop.thumbnail_url ? crop.thumbnail_url : placeholder_image, alt: crop.name, class: 'img img-card'), - crop + crop_path(slug: crop.slug) .text - %h3.crop-name= link_to crop, crop + %h3.crop-name= link_to crop.name, crop_path(slug: crop.slug) %h5.crop-sci-name -   - = crop.scientific_names.first&.name + = crop.scientific_names.first diff --git a/app/views/crops/index.html.haml b/app/views/crops/index.html.haml index 9458b31b9..427412019 100644 --- a/app/views/crops/index.html.haml +++ b/app/views/crops/index.html.haml @@ -22,8 +22,8 @@ %h2= t('.title') = will_paginate @crops .index-cards - - @crops.each do |crop| - = render 'crops/search_result', crop: crop + - @crops.each do |c| + = render 'crops/thumbnail', crop: c = will_paginate @crops diff --git a/app/views/home/_crops.html.haml b/app/views/home/_crops.html.haml index 5744bc22d..17c25cd4d 100644 --- a/app/views/home/_crops.html.haml +++ b/app/views/home/_crops.html.haml @@ -1,4 +1,4 @@ - cache cache_key_for(Crop, 'homepage'), expires_in: 1.day do .index-cards - - CropSearchService.random_with_photos(16).each do |crop| - = render 'crops/search_result', crop: crop \ No newline at end of file + - CropSearchService.random_with_photos(16).each do |c| + = render 'crops/thumbnail', crop: c \ No newline at end of file