mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-23 17:22:24 -04:00
UI for removing photos from plantings
This commit is contained in:
13
app/controllers/photo_associations_controller.rb
Normal file
13
app/controllers/photo_associations_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class PhotoAssociationsController < ApplicationController
|
||||
before_action :authenticate_member!
|
||||
respond_to :json, :html
|
||||
|
||||
def destroy
|
||||
@photo = Photo.find(params[:photo_id])
|
||||
if params[:type] == 'planting'
|
||||
@planting = Planting.find(params[:planting_id])
|
||||
@photo.plantings.delete(@planting) if @planting.owner == current_user && @photo.owner == current_user
|
||||
end
|
||||
respond_with(@photo)
|
||||
end
|
||||
end
|
||||
@@ -12,6 +12,15 @@
|
||||
%p= image_tag(@photo.fullsize_url, alt: @photo.title, class: 'img')
|
||||
|
||||
.col-md-4
|
||||
%p
|
||||
- if can? :destroy, @photo
|
||||
= link_to @photo, method: :delete,
|
||||
data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-trash{ title: "Delete" }
|
||||
|
||||
- if can? :edit, @photo
|
||||
= link_to edit_photo_path(@photo), class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-pencil{ title: "Edit" }
|
||||
%p
|
||||
%strong Posted by:
|
||||
= link_to @photo.owner, @photo.owner
|
||||
@@ -25,24 +34,23 @@
|
||||
|
||||
%p= link_to "View on Flickr", @photo.link_url
|
||||
|
||||
- if can? :destroy, @photo
|
||||
= link_to 'delete',
|
||||
@photo, method: :delete,
|
||||
data: { confirm: 'Are you sure?' },
|
||||
class: 'btn btn-default btn-xs'
|
||||
- if can? :edit, @photo
|
||||
= link_to 'edit', edit_photo_path(@photo), class: 'btn btn-default btn-xs'
|
||||
|
||||
|
||||
- if @photo.associations?
|
||||
%h4 This photo depicts:
|
||||
%ul
|
||||
- @photo.plantings.each do |p|
|
||||
%li= link_to t('.planting', planting: p.to_s, owner: p.owner.to_s), planting_path(p)
|
||||
%li
|
||||
= link_to t('.planting', planting: p.to_s, owner: p.owner.to_s), planting_path(p)
|
||||
- if can? :edit, @photo
|
||||
= link_to photo_associations_path(photo_id: @photo.id,
|
||||
type: 'planting', planting_id: p.id), method: 'delete',
|
||||
class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-remove{ title: "Remove link" }
|
||||
|
||||
- @photo.harvests.each do |h|
|
||||
%li= link_to t('.harvest', crop: h.crop.name, owner: h.owner.to_s), harvest_path(h)
|
||||
|
||||
- @photo.gardens.each do |g|
|
||||
%li= link_to t('.garden', garden: g.to_s, owner: g.owner.to_s), garden_path(g)
|
||||
|
||||
- @photo.seeds.each do |s|
|
||||
%li= link_to t('.seed', seed: s.to_s, owner: s.owner.to_s), seed_path(s)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ Growstuff::Application.routes.draw do
|
||||
resources :members
|
||||
|
||||
resources :photos
|
||||
delete 'photo_associations' => 'photo_associations#destroy'
|
||||
|
||||
resources :authentications, only: [:create, :destroy]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user