From 964c243266e90a808e319d8fb9b79b3342edac0f Mon Sep 17 00:00:00 2001 From: oliverochman Date: Thu, 3 Sep 2020 14:37:34 +0200 Subject: [PATCH] minor changes --- Gemfile | 2 +- Gemfile.lock | 5 +++-- app/controllers/api/v1/listings_controller.rb | 4 +++- app/models/listing.rb | 2 +- app/serializers/listing_show_serializer.rb | 10 ++++++---- config/credentials.yml.enc | 2 +- db/seeds.rb | 6 +++--- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 9058e31..5ff28f7 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rack-cors', require: 'rack/cors' gem 'active_model_serializers' gem 'devise_token_auth' gem 'geocoder' -gem 'aws-sdk-s3' +gem 'aws-sdk-s3', require: false gem 'stripe-rails' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 7f7c0eb..13625d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,10 +100,11 @@ GEM railties (>= 4.1.0) responders warden (~> 1.2.3) - devise_token_auth (1.1.3) + devise_token_auth (1.1.4) bcrypt (~> 3.0) devise (> 3.5.2, < 5) rails (>= 4.2.0, < 6.1) + sprockets (= 3.7.2) diff-lcs (1.4.4) docile (1.3.2) erubi (1.9.0) @@ -219,7 +220,7 @@ GEM spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (4.0.2) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) diff --git a/app/controllers/api/v1/listings_controller.rb b/app/controllers/api/v1/listings_controller.rb index 69a1ca4..86cd61a 100644 --- a/app/controllers/api/v1/listings_controller.rb +++ b/app/controllers/api/v1/listings_controller.rb @@ -9,10 +9,12 @@ def index end def show + binding.pry listing = Listing.find(params[:id]) render json: listing, serializer: ListingShowSerializer - rescue StandardError + rescue StandardError => e + binding.pry render json: { message: 'Unfortunately the listing could not be found' }, status: 422 end diff --git a/app/models/listing.rb b/app/models/listing.rb index 9bd2144..bc85947 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -2,7 +2,7 @@ class Listing < ApplicationRecord validates_presence_of :category, :lead, :scene, :address, :description, :price enum scene: [:indoor, :outdoor] - has_many_attached :image + has_many_attached :images geocoded_by :address diff --git a/app/serializers/listing_show_serializer.rb b/app/serializers/listing_show_serializer.rb index c85da09..4580791 100644 --- a/app/serializers/listing_show_serializer.rb +++ b/app/serializers/listing_show_serializer.rb @@ -1,13 +1,15 @@ class ListingShowSerializer < ActiveModel::Serializer include Rails.application.routes.url_helpers - attributes :id, :category, :lead, :scene, :description, :address, :price, :image - def image - return nil unless object.image.attached? + attributes :id, :category, :lead, :scene, :description, :address, :price, :images + + def images + return nil unless object.images.attached? if Rails.env.test? rails_blob_url(object.image) else - object.image.service_url(expires_in:1.hour, disposition: 'inline') + binding.pry + object.images.service_url(expires_in:1.hour, disposition: 'inline') end end end diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index d3e81be..45b3492 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -N6lYsC7CzNt6smGvxLSozdySGaOMEjJwVzHS3Q/rNAbezjEG5XhoZkOxtez05nkPn8BTIlvhI78pkbBYMS4/cIMMspMEgL/kVor6j1zZ+QIXPypgmajYgfh49+claeeiFd+3KM0Pl5ieYItk/BBBaYDL0BgmlKOURcWOVt3Tyx6DG3Gd4kPIPVd66j6UQBJSMNitkh2a4fBcJT6FyceW8UOi4DbSrMgSFiqAsy2kKSxbies9PuQ4xWMt3J5333ZHEAF4rH675YPjydv1H/VnJ/9Z8RxMq5PpLCrurlpKWCFP9uXgHDY2ZXDG6Ol6XxVPWcS4hHC9uk7ozl2dLWv9NqliShEiDLufgYwLXww16VRqLFw+2foQdGbZXFgW8alGHzAYC/hUezJ7gFieWXDgm2Fd7ogq9fHg4FewVtdRv+b2iiwIDemBNHR2Mxh4saC6G5ACHtLKOJQzt5DAg7jOsFi/tbnCKhytmeyn/0Xf9PxLvHllIMoGz62vALhy4Y6HiDcGKkbxo9YLkEL1Z+zJLgZxxqURy/pql6Pc+CWmbmTLPFZqu7NpPqBZNEEPsUq65FVuLfzsG9EVbh55uWo2/EddxRKfQwgZdRLx0VtpEW01WbzGcv9uGGvibeaQtbo8cO+XpI0z--nucIdQ3lUVoge1IQ--6/hOTiG79SDnqEawaILx6Q== \ No newline at end of file +JojYHZfQ8xGbq+Rmor3yocTh4FST1uT3j7X+UQmhP/q6LOWIfEhlWaSYC58taSipzudwY5wAqM82+wrgQElVPruM9MhHJQQ0bGPddb31948ppD2n14OOdSVymCD3TuS1vfEYSmbUJJFGmEz4rXMIpPHGKV3/+xfdz1vZypVl3nB/Y/7Kw6Qbw3Mcnjq8uhxQAjg/xChKDZPSNoL8SiICJYZscM+TSQNS/LPR1BRuwRiWMHbhcN32+Bo2WxZLxfmcrue/vf1AH+FYKaTM8mUL0wLvOHEbEj4cSVUagigj8qJJrPFuFeH9RWMAkaqNLXRPcNdS+1M6BCLU4FEBwMegyNhXErWTNgG9QGcuO2w8RB3mvbcKgmz6FvxAitr4ndKfgECf77USxw9oDgMitLzCgHTlD3IS+1/J3Lf8Ij3CpcHIwL7j2y6oratPUlxX6wzfSNfI5HpizSkW7pgC7MnRsppoT8nUS4wdZGEIyR9yfUNNILTbOne+CvD66cmvgui/2brYHFXDLdJ0KgqEMNd3mSyzBnBgiHMbe6/IDgOldwONvyT41w7bo6jTzW8sn1OqoGEnt66GuG6uTlIp022x1qLoKHD6GSfhaggCChsPZB74BrRVtMIJ6CF4n3ik9os=--fceoVIu+RyRkWKWu--TnIlvtTi6ySWFRNdFJjsBw== \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index b4a40c1..c53ba84 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -14,7 +14,7 @@ landlord_id: user.id ) file = URI.open('https://www.quickanddirtytips.com/sites/default/files/images/12186/Parking-Lot-of-deas.jpg') -free_listing_1.image.attach(io: file, filename: 'first.jpg') +free_listing_1.images.attach(io: file, filename: 'first.jpg') free_listing_2 = Listing.create( category: 'Parking spot', @@ -26,7 +26,7 @@ landlord_id: user.id ) file = URI.open('https://www.pymnts.com/wp-content/uploads/2018/03/parkingspot.jpg') -free_listing_2.image.attach(io: file, filename: 'second.jpg') +free_listing_2.images.attach(io: file, filename: 'second.jpg') free_listing_3 = Listing.create( category: 'Parking spot', @@ -38,4 +38,4 @@ landlord_id: user.id ) file = URI.open('https://parkeasier.com/wp-content/uploads/2014/12/Homepage_Find_a_Spot_section2.jpg') -free_listing_3.image.attach(io: file, filename: 'third.jpg') \ No newline at end of file +free_listing_3.images.attach(io: file, filename: 'third.jpg') \ No newline at end of file