Skip to content

Commit 5cd671c

Browse files
committed
Added placeholder listing image and touched up the seed file
1 parent c62305d commit 5cd671c

File tree

6 files changed

+1832
-5
lines changed

6 files changed

+1832
-5
lines changed
5.05 KB
Loading

app/models/listing.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Listing < ApplicationRecord
88
has_many :favourite_listings, dependent: :destroy
99
has_many :favourited_by, through: :favourite_listings, source: :user
1010

11-
has_one :purchase
11+
has_one :purchase, dependent: :destroy
1212

1313
validates :title, :price, :condition_id, :brand_id, :category_id, presence: :true
1414
validates :price, numericality: { greater_than: 0 }

app/views/shared/_display_listings.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<% if listing.picture.attached? %>
66
<%= image_tag listing.picture.service_url, class: "card-img-top" %>
77
<% else %>
8-
<%= image_tag "placeholder-avatar.png", class: "card-img-top" %>
8+
<%= image_tag "placeholder-listing.png", alt: "listing image not attached", class: "card-img-top" %>
99
<% end %>
1010
<hr>
1111
<div class="card-body d-flex flex-column justify-content-between">

app/views/shared/_listing_details.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<div class="col">
77
<% if @listing.picture.attached? %>
88
<%= image_tag @listing.picture.service_url %>
9+
<% else %>
10+
<%= image_tag "placeholder-listing.png", alt: "listing image not attached" %>
911
<% end %>
1012
</div>
1113

db/seeds.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def total_count()
5555
end
5656

5757
# Generate random user accounts
58-
for i in 1..30
58+
for i in 1..10
5959
User.create(
6060
full_name: Faker::Name.name,
6161
email: Faker::Internet.email,
@@ -65,7 +65,8 @@ def total_count()
6565
)
6666
end
6767

68-
for i in 1..70
68+
#Create listing.
69+
for i in 1..48
6970
Listing.create(
7071
user_id: rand(1..User.count),
7172
condition_id: rand(1..Condition.count),
@@ -77,7 +78,7 @@ def total_count()
7778
)
7879
end
7980

80-
#attach image
81+
#Attach image to listings - Ensure that the stock images are attached correctly accordingly to the listing's brand and category.
8182
listings = Listing.all
8283

8384
listings.each do |listing|

0 commit comments

Comments
 (0)