From 5cef4d728ca23aab4dda520804b2d2804705cfb8 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Jul 2019 13:20:57 +1200 Subject: [PATCH] Adding photos directly to a post --- app/models/photo.rb | 2 +- app/models/post.rb | 5 +++++ app/views/photos/_associations.html.haml | 5 +++++ app/views/posts/_actions.html.haml | 2 ++ app/views/posts/show.html.haml | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index 2481fab2e..40620b6b5 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -1,7 +1,7 @@ class Photo < ApplicationRecord include Ownable - PHOTO_CAPABLE = %w(Garden Planting Harvest Seed).freeze + PHOTO_CAPABLE = %w(Garden Planting Harvest Seed Post).freeze has_many :photographings, foreign_key: :photo_id, dependent: :destroy, inverse_of: :photo has_many :crops, through: :photographings diff --git a/app/models/post.rb b/app/models/post.rb index 50be9bfc7..0427ada70 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -2,6 +2,7 @@ class Post < ApplicationRecord extend FriendlyId include Likeable friendly_id :author_date_subject, use: %i(slugged finders) + include PhotoCapable # # Relationships @@ -48,6 +49,10 @@ class Post < ApplicationRecord end end + def owner_id + author_id + end + def to_s subject end diff --git a/app/views/photos/_associations.html.haml b/app/views/photos/_associations.html.haml index 7486321ad..5e05c27e2 100644 --- a/app/views/photos/_associations.html.haml +++ b/app/views/photos/_associations.html.haml @@ -1,6 +1,11 @@ %h4 This photo depicts: %p %ul.associations + - @photo.posts.each do |post| + %li + = post_icon + = link_to post.subject, post + = render "association_delete_button", photo: @photo, type: 'post', thing: post - @photo.plantings.each do |planting| %li = planting_icon diff --git a/app/views/posts/_actions.html.haml b/app/views/posts/_actions.html.haml index 393a3d58a..30617062f 100644 --- a/app/views/posts/_actions.html.haml +++ b/app/views/posts/_actions.html.haml @@ -6,6 +6,8 @@ = link_to edit_post_path(post), class: 'dropdown-item' do = edit_icon Edit + = add_photo_button(post, classes: "dropdown-item") + .dropdown-divider - if can? :delete, post = link_to post_path(post), class: 'dropdown-item text-danger', data: { confirm: 'Are you sure?' } do = delete_icon diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index f73a8aecf..33515fe1c 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -40,6 +40,9 @@ = render 'posts/actions', post: @post .card-body = render 'posts/single', post: @post + .index-cards + - @post.photos.each do |photo| + = render 'photos/thumbnail', photo: photo .card-footer = render 'posts/likes', post: @post