One view for showing photos on an item

This commit is contained in:
Brenda Wallace
2017-12-17 10:53:11 +13:00
parent 2a4fd57050
commit 2394f4d237
9 changed files with 24 additions and 37 deletions

View File

@@ -18,6 +18,7 @@ class HarvestsController < ApplicationController
def show
@matching_plantings = matching_plantings if @harvest.owner == current_member
@photos = @harvest.photos.order(created_at: :desc).paginate(page: params[:page])
respond_with(@harvest)
end

View File

@@ -31,6 +31,7 @@ class PlantingsController < ApplicationController
@planting = Planting.includes(:owner, :crop, :garden, :photos)
.friendly
.find(params[:id])
@photos = @planting.photos.order(created_at: :desc).includes(:owner).paginate(page: params[:page])
respond_with @planting
end

View File

@@ -48,15 +48,4 @@
:growstuff_markdown
#{ @harvest.description != "" ? strip_tags(@harvest.description) : "No description given." }
- if !@harvest.photos.empty? || (can?(:edit, @harvest) && can?(:create, Photo))
%h2 Pictures
%ul.thumbnails
- @harvest.photos.each do |p|
.col-md-2.six-across
= render partial: 'photos/thumbnail', locals: { photo: p }
- if can?(:create, Photo) && can?(:edit, @harvest)
.col-md-2
.thumbnail{ style: 'height: 220px' }
%p{ style: 'text-align: center; padding-top: 50px' }
= link_to "Add photo", new_photo_path(type: "harvest", id: @harvest.id), class: 'btn btn-primary'
= render 'photos/item_photos', item: @harvest, type: 'harvest', photos: @photos

View File

@@ -0,0 +1,16 @@
- if photos.size.positive? || (can?(:edit, item) && can?(:create, Photo))
%h2 Photos
- if photos.size.positive?
.row
.pagination
= page_entries_info photos
= will_paginate photos
.row
- photos.each do |photo|
.col-md-2.six-across= render 'photos/thumbnail', photo: photo
- if can?(:create, Photo) && can?(:edit, item)
.col-md-2
.thumbnail
= link_to new_photo_path(type: type, id: item.id), class: 'btn btn-primary' do
%span.glyphicon.glyphicon-camera{ title: "Add photo" }
Add photo

View File

@@ -83,15 +83,4 @@
:growstuff_markdown
#{ @planting.description != "" ? strip_tags(@planting.description) : "No description given." }
- if !@planting.photos.empty? || (can?(:edit, @planting) && can?(:create, Photo))
%h2 Photos
.row
- @planting.photos.includes(:owner).each do |p|
.col-md-2.six-across
= render partial: 'photos/thumbnail', locals: { photo: p }
- if can?(:create, Photo) && can?(:edit, @planting)
.col-md-2
.thumbnail{ style: 'height: 220px' }
%p{ style: 'text-align: center; padding-top: 50px' }
= link_to "Add photo", new_photo_path(type: "planting", id: @planting.id), class: 'btn btn-primary'
= render 'photos/item_photos', item: @planting, type: 'planting', photos: @photos

View File

@@ -76,15 +76,4 @@
= link_to "purchase seeds via Ebay",
crop_ebay_seeds_url(@seed.crop), target: "_blank", rel: "noopener noreferrer"
- if @photos.size.positive?
.row
.pagination
= page_entries_info @photos
= will_paginate @photos
.row
- @photos.each do |p|
.col-md-2.six-across
= render 'photos/thumbnail', photo: p
- if can?(:create, Photo) && can?(:edit, @seed)
.col-md-2
= link_to "Add photo", new_photo_path(type: "seed", id: @seed.id), class: 'btn btn-primary'
= render 'photos/item_photos', item: @seed, type: 'seed', photos: @photos

View File

@@ -6,6 +6,7 @@ describe "harvests/show" do
before do
controller.stub(:current_user) { nil }
assign(:harvest, harvest)
assign(:photos, harvest.photos.paginate(page: 1))
render
end

View File

@@ -12,6 +12,7 @@ describe "plantings/show" do
before(:each) do
assign(:planting, planting)
assign(:photos, planting.photos.paginate(page: 1))
controller.stub(:current_user) { member }
end

View File

@@ -5,7 +5,7 @@ describe "seeds/show" do
controller.stub(:current_user) { nil }
@seed = FactoryBot.create(:seed)
assign(:seed, @seed)
assign(:photos, @seed.photos)
assign(:photos, @seed.photos.paginate(page: 1))
end
it "renders attributes in <p>" do