Skip to content

Commit

Permalink
Merge pull request #37 from IliaZolas/adding-pictures
Browse files Browse the repository at this point in the history
pictures added in the seed file
  • Loading branch information
IliaZolas authored Nov 26, 2020
2 parents ad2db94 + a6e1f14 commit 8710a31
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 82 deletions.
3 changes: 2 additions & 1 deletion app/models/studio.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Studio < ApplicationRecord
class Studio < ApplicationRecord
belongs_to :user
validates :title, presence: true, uniqueness: true, length: { in: 3..60 }
validates :address, presence: true
Expand All @@ -7,4 +7,5 @@ class Studio < ApplicationRecord
geocoded_by :address
after_validation :geocode, if: :will_save_change_to_address?
has_many :bookings
has_one_attached :photo
end
4 changes: 3 additions & 1 deletion app/views/studios/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<div class="card-header">
<h2><%= studio.title %></h2>
</div>
<img class="card-img-top" src="https://static.questiondeson.com/img/studios/a/1-studio-a-2019-front.jpg" alt="Card image cap">
<% if studio.photo.attached? %>
<%= cl_image_tag studio.photo.key, class: "card-img-top", height: 180 %>
<% end %>
<div class="card-body">
<div class="d-flex justify-content-between align-items-start">
<p class="card-text col-9 card-studio-address"><%= studio.address %></p>
Expand Down
7 changes: 4 additions & 3 deletions app/views/studios/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="studio-card-container">
<div class="studio-show-card shadow mt-5 mb-5 rounded">
<img class="w-100 shadow rounded" src='https://images.pexels.com/photos/164938/pexels-photo-164938.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260'>
<% if @studio.photo.attached? %>
<%= cl_image_tag @studio.photo.key, crop: :fill, class: "w-100 shadow rounded", height: 750 %>
<% end %>
<div class="p-5">
<div class="d-flex justify-content-between">
<h1 class="studio-title"><%= @studio.title %></h1>
Expand All @@ -18,5 +20,4 @@
</div>
</div>
</div>
</div>

</div>
168 changes: 91 additions & 77 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
# "title"/"address"/"price"/"description"
# require 'faker'
require "open-uri"
require 'faker'
puts "cleaning data base"

Expand Down Expand Up @@ -55,89 +47,111 @@
password: "123456",
last_name: Faker::Name.first_name,
first_name: Faker::Name.last_name,

)
user.save!
end

puts "creating Makers 8 Studios"
file = URI.open('https://images.unsplash.com/photo-1558474566-cbeb8b92cf48?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80')
studio1 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue Marterey 36, 1005 lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: jonas
)
studio1.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio1.save!
file = URI.open('https://images.unsplash.com/photo-1603074256912-949e556ba901?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80')
studio2 = Studio.new(
title: Faker::Book.unique.title,
address: "Avenue du Leman 19, 1005 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: jonas
)
studio2.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio2.save!
file = URI.open('https://images.unsplash.com/photo-1568246605205-f8df0dde3c35?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80')
studio3 = Studio.new(
title: Faker::Book.unique.title,
address: "Boulevard de Grancy 1, 1006 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ilia
)
studio3.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio3.save!
file = URI.open('https://images.unsplash.com/photo-1597083610113-6e274e92ce55?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80')
studio4 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue Beau-Sejour 27, 1003 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ilia
)
studio4.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio4.save!
file = URI.open
studio5 = Studio.new(
title: Faker::Book.unique.title,
address: "Avenue de la gare 46, 1001 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: elodie
)
studio5.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio5.save!
file = URI.open
studio6 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue du tunnel 7, 1005 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: elodie
)
studio6.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio6.save!
file = URI.open
studio7 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue du tunnel 1, 1005 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ghizlaine
)
studio7.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio7.save!
file = URI.open
studio8 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue du Simplon 35, 1006 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ghizlaine
)
studio8.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio8.save!

studio1 = Studio.new(
title: Faker::Book.unique.title,
address: "rue Marterey 36, 1005 lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: jonas
)
studio1.save!
studio2 = Studio.new(
title: Faker::Book.unique.title,
address: "Avenue du Leman 19, 1005 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: jonas
)
studio2.save!
studio3 = Studio.new(
title: Faker::Book.unique.title,
address: "Boulvevard de Grancy 1, 1006 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ilia
)
studio3.save!
studio4 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue Beau-Sejour 27, 1003 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ilia
)
studio4.save!
studio5 = Studio.new(
title: Faker::Book.unique.title,
address: "Avenue de la gare 46, 1001 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: elodie
)
studio5.save!
studio6 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue du tunnel 7, 1005 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: elodie
)
studio6.save!
studio7 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue du tunnel 1, 1005 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ghizlane
)
studio7.save!
studio8 = Studio.new(
title: Faker::Book.unique.title,
address: "Rue du Simplon 35, 1006 Lausanne",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: ghizlane
)
studio8.save!

puts 'Creating 10 fake studios...'
photos = ["https://images.unsplash.com/photo-1574517947730-55cb23e608c2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80", "https://images.unsplash.com/photo-1559732277-7453b141e3a1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80",
"https://images.unsplash.com/photo-1563330232-57114bb0823c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80", "https://images.unsplash.com/photo-1463421585849-6b0acf2c9257?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1332&q=80",
"https://images.unsplash.com/photo-1553526171-9e305610ccdd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1334&q=80", "https://images.unsplash.com/photo-1571916962125-ea2d1c8bde47?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1649&q=80",
"https://images.unsplash.com/photo-1585842351739-9e872cfacb4a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1651&q=80", "https://images.unsplash.com/photo-1592060567920-a46e1bffb28e?ixlib=rb-1.2.1&auto=format&fit=crop&w=1334&q=80",
"https://images.unsplash.com/photo-1555724950-dcd0957571f8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80", "https://images.unsplash.com/photo-1560844915-bb3189e146ec?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1731&q=80"]
10.times do
file = URI.open(photos.first)

puts 'Creating 20 fake studios...'
20.times do
studio = Studio.new(
title: Faker::Book.unique.title,
address: "#{Faker::Address.street_address}, #{Faker::Address.city}",
price: rand(85..214),
description: Faker::Lorem.paragraph_by_chars(number: 500, supplemental: false),
user: User.all.sample
)
studio.photo.attach(io: file, filename: 'nes.png', content_type: 'image/jpg')
studio.save!
photos.delete_at(0)
end

puts 'Finished!'
Expand Down

0 comments on commit 8710a31

Please sign in to comment.