Adding photos directly to a post

This commit is contained in:
Brenda Wallace
2019-07-08 13:20:57 +12:00
parent cc271b2cc3
commit 5cef4d728c
5 changed files with 16 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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