mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-14 11:15:48 -04:00
One view for showing photos on an item
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
16
app/views/photos/_item_photos.haml
Normal file
16
app/views/photos/_item_photos.haml
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user