From 41eedd438020bba14921a31b021197ddb9d34372 Mon Sep 17 00:00:00 2001 From: Yasmine BERRADA Date: Fri, 26 Nov 2021 14:44:44 +0100 Subject: [PATCH] act as taggable fonctionne pour filtrer les event par les hobbies du user --- Gemfile | 1 + Gemfile.lock | 5 +++ app/assets/stylesheets/components/_index.scss | 1 + app/assets/stylesheets/components/_tags.scss | 38 +++++++++++++++++++ app/controllers/activities_controller.rb | 10 ++++- app/models/user.rb | 1 + app/views/activities/index.html.erb | 22 +++++++++++ ...on_migration.acts_as_taggable_on_engine.rb | 37 ++++++++++++++++++ ...ique_indices.acts_as_taggable_on_engine.rb | 26 +++++++++++++ ...ache_to_tags.acts_as_taggable_on_engine.rb | 20 ++++++++++ ...ggable_index.acts_as_taggable_on_engine.rb | 15 ++++++++ ...or_tag_names.acts_as_taggable_on_engine.rb | 15 ++++++++ ..._on_taggings.acts_as_taggable_on_engine.rb | 23 +++++++++++ ..._to_taggings.acts_as_taggable_on_engine.rb | 17 +++++++++ ...20211126113845_add_category_to_activity.rb | 5 +++ db/schema.rb | 33 +++++++++++++++- db/seeds.rb | 29 ++++++++------ 17 files changed, 283 insertions(+), 15 deletions(-) create mode 100644 app/assets/stylesheets/components/_tags.scss create mode 100644 db/migrate/20211126102607_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20211126102608_add_missing_unique_indices.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20211126102609_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20211126102610_add_missing_taggable_index.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20211126102611_change_collation_for_tag_names.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20211126102612_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20211126102613_add_tenant_to_taggings.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20211126113845_add_category_to_activity.rb diff --git a/Gemfile b/Gemfile index 0e0b247..6e75ed5 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,7 @@ gem 'pg_search', '~> 2.3.0' gem "geocoder" gem 'pundit' gem 'faker' +gem 'acts-as-taggable-on', '~> 8.1' group :development, :test do gem 'pry-byebug' gem 'pry-rails' diff --git a/Gemfile.lock b/Gemfile.lock index a76e957..7df5ca0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,6 +56,8 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) zeitwerk (~> 2.2, >= 2.2.2) + acts-as-taggable-on (8.1.0) + activerecord (>= 5.0, < 6.2) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) autoprefixer-rails (10.2.5.0) @@ -135,6 +137,8 @@ GEM nokogiri (1.12.5) mini_portile2 (~> 2.6.1) racc (~> 1.4) + nokogiri (1.12.5-x86_64-linux) + racc (~> 1.4) orm_adapter (0.5.0) pg (1.2.3) pg_search (2.3.5) @@ -268,6 +272,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + acts-as-taggable-on (~> 8.1) autoprefixer-rails (= 10.2.5) bootsnap (>= 1.4.2) byebug diff --git a/app/assets/stylesheets/components/_index.scss b/app/assets/stylesheets/components/_index.scss index 94f82c0..b9f1f24 100644 --- a/app/assets/stylesheets/components/_index.scss +++ b/app/assets/stylesheets/components/_index.scss @@ -13,3 +13,4 @@ @import "sweetalert"; @import "calendar"; @import "card-user"; +@import "tags"; diff --git a/app/assets/stylesheets/components/_tags.scss b/app/assets/stylesheets/components/_tags.scss new file mode 100644 index 0000000..07831d9 --- /dev/null +++ b/app/assets/stylesheets/components/_tags.scss @@ -0,0 +1,38 @@ +.title{ + margin-top: 20px; + margin-bottom: 20px; +} +.wrapper-tags{ + -webkit-box-align: center !important; + display: flex !important; + align-items: center !important; + margin-top: 20px; + margin-bottom: 20px; +} + +.tags{ + display: inline-block !important; + white-space: nowrap !important; + padding-right: 8px !important; + padding-top: 4px !important; + padding-bottom: 4px !important; + width: 100% !important; +} + +.tags-precision{ + cursor: pointer !important; + text-align: center !important; + border: 1px solid rgb(221, 221, 221) !important; + background-color: rgb(255, 255, 255) !important; + outline: none !important; + margin: 0px !important; + border-radius: 30px !important; + color: rgb(34, 34, 34) !important; + font-family: Circular, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif !important; + position: relative !important; + padding: 10px 16px !important; + font-size: 12px !important; + line-height: 16px !important; + width: 100% !important; + font-size: larger; +} diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index e0d1fbd..fd1a49c 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -1,13 +1,15 @@ class ActivitiesController < ApplicationController def index @activities = policy_scope(Activity).order(created_at: :desc) + # authorize @activity ## RETURN THE RESULTS FROM THE HOMEPAGE SEARCH # check if the user typed an address in the searchbar if params[:query].present? + # and corresponding to current user's hobbies (each user has 3 hobbies) + @activities = Activity.where(category: current_user.hobby_list) # if yes, render all activities located XX km around this address - @activities = Activity.search_by_place(params[:query]).near(params[:query], 100) - # @activities = Activity.near(params[:query], 6) + @activities = @activities.search_by_place(params[:query]).near(params[:query], 100) # return only the activity which are not full @activities = @activities.select { |activity| activity.bookings.length <= activity.capacity_max } @title = "We found #{@activities.length} activities near #{params[:query]}" @@ -20,11 +22,15 @@ def index # if the user didn't typed an address, check if he typed a date elsif params[:start_date].present? + # and corresponding to current user hobbies (each user has 3 hobbies) + @activities = Activity.where(category: current_user.hobby_list) # if yes, render all activities with the same start date @activities = @activities.filter { |activity| activity.start_date >= params[:start_date] } @title = "We found #{@activities.length} activities in the world" # if the user didn't type any place or date else + # and corresponding to current user hobbies (each user has 3 hobbies) + @activities = Activity.where(category: current_user.hobby_list) # render all activities not fully booked @activities = @activities.select { |activity| activity.bookings.length <= activity.capacity_max } # filter activities with a future start date diff --git a/app/models/user.rb b/app/models/user.rb index 64dd5ec..52c6cbb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,6 +8,7 @@ class User < ApplicationRecord has_many :activities, through: :bookings has_many :travels, dependent: :destroy has_one_attached :photo + acts_as_taggable_on :hobbies validates :photo, presence: true validates :first_name, :last_name, presence: true diff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erb index aea79a3..3882de2 100644 --- a/app/views/activities/index.html.erb +++ b/app/views/activities/index.html.erb @@ -1,3 +1,23 @@ + +
+
+
Filter all activities by categories 🔥
+
+
+ Sports 🏓 + Nature 🏔 + Visiting 🗽 + Food 🍜 + Bars 🍺 + Tech 💾 + Arts 🎨 + Crafts 🪚 + Dancing 💃🏾🕺🏼 + Singing 🎤 + Shopping 🛍 +
+
+
@@ -38,3 +58,5 @@ data-mapbox-markers-value="<%= @markers.to_json %>" data-mapbox-api-key-value="<%= ENV['MAPBOX_API_KEY'] %>">
+ +<%= console %> diff --git a/db/migrate/20211126102607_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20211126102607_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..51a01a0 --- /dev/null +++ b/db/migrate/20211126102607_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb @@ -0,0 +1,37 @@ +# This migration comes from acts_as_taggable_on_engine (originally 1) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end +else + class ActsAsTaggableOnMigration < ActiveRecord::Migration; end +end +ActsAsTaggableOnMigration.class_eval do + def self.up + create_table ActsAsTaggableOn.tags_table do |t| + t.string :name + t.timestamps + end + + create_table ActsAsTaggableOn.taggings_table do |t| + t.references :tag, foreign_key: { to_table: ActsAsTaggableOn.tags_table } + + # You should make sure that the column created is + # long enough to store the required class names. + t.references :taggable, polymorphic: true + t.references :tagger, polymorphic: true + + # Limit is created to prevent MySQL error on index + # length for MyISAM table type: http://bit.ly/vgW2Ql + t.string :context, limit: 128 + + t.datetime :created_at + end + + add_index ActsAsTaggableOn.taggings_table, :tag_id + add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx' + end + + def self.down + drop_table ActsAsTaggableOn.taggings_table + drop_table ActsAsTaggableOn.tags_table + end +end diff --git a/db/migrate/20211126102608_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20211126102608_add_missing_unique_indices.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..93a4587 --- /dev/null +++ b/db/migrate/20211126102608_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -0,0 +1,26 @@ +# This migration comes from acts_as_taggable_on_engine (originally 2) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end +else + class AddMissingUniqueIndices < ActiveRecord::Migration; end +end +AddMissingUniqueIndices.class_eval do + def self.up + add_index ActsAsTaggableOn.tags_table, :name, unique: true + + remove_index ActsAsTaggableOn.taggings_table, :tag_id if index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) + remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx' + add_index ActsAsTaggableOn.taggings_table, + [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], + unique: true, name: 'taggings_idx' + end + + def self.down + remove_index ActsAsTaggableOn.tags_table, :name + + remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_idx' + + add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) + add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx' + end +end diff --git a/db/migrate/20211126102609_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20211126102609_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..2bdad22 --- /dev/null +++ b/db/migrate/20211126102609_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -0,0 +1,20 @@ +# This migration comes from acts_as_taggable_on_engine (originally 3) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end +else + class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end +end +AddTaggingsCounterCacheToTags.class_eval do + def self.up + add_column ActsAsTaggableOn.tags_table, :taggings_count, :integer, default: 0 + + ActsAsTaggableOn::Tag.reset_column_information + ActsAsTaggableOn::Tag.find_each do |tag| + ActsAsTaggableOn::Tag.reset_counters(tag.id, ActsAsTaggableOn.taggings_table) + end + end + + def self.down + remove_column ActsAsTaggableOn.tags_table, :taggings_count + end +end diff --git a/db/migrate/20211126102610_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20211126102610_add_missing_taggable_index.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..3f30b37 --- /dev/null +++ b/db/migrate/20211126102610_add_missing_taggable_index.acts_as_taggable_on_engine.rb @@ -0,0 +1,15 @@ +# This migration comes from acts_as_taggable_on_engine (originally 4) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end +else + class AddMissingTaggableIndex < ActiveRecord::Migration; end +end +AddMissingTaggableIndex.class_eval do + def self.up + add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :context], name: 'taggings_taggable_context_idx' + end + + def self.down + remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx' + end +end diff --git a/db/migrate/20211126102611_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20211126102611_change_collation_for_tag_names.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..5464deb --- /dev/null +++ b/db/migrate/20211126102611_change_collation_for_tag_names.acts_as_taggable_on_engine.rb @@ -0,0 +1,15 @@ +# This migration comes from acts_as_taggable_on_engine (originally 5) +# This migration is added to circumvent issue #623 and have special characters +# work properly +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end +else + class ChangeCollationForTagNames < ActiveRecord::Migration; end +end +ChangeCollationForTagNames.class_eval do + def up + if ActsAsTaggableOn::Utils.using_mysql? + execute("ALTER TABLE #{ActsAsTaggableOn.tags_table} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") + end + end +end diff --git a/db/migrate/20211126102612_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20211126102612_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..7c39589 --- /dev/null +++ b/db/migrate/20211126102612_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,23 @@ +# This migration comes from acts_as_taggable_on_engine (originally 6) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end +else + class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end +end +AddMissingIndexesOnTaggings.class_eval do + def change + add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id + add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_id + add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_type + add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, :tagger_id + add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context + + unless index_exists? ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] + add_index ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] + end + + unless index_exists? ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + end + end +end diff --git a/db/migrate/20211126102613_add_tenant_to_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20211126102613_add_tenant_to_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..2e6da51 --- /dev/null +++ b/db/migrate/20211126102613_add_tenant_to_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,17 @@ +# This migration comes from acts_as_taggable_on_engine (originally 7) +if ActiveRecord.gem_version >= Gem::Version.new('5.0') + class AddTenantToTaggings < ActiveRecord::Migration[4.2]; end +else + class AddTenantToTaggings < ActiveRecord::Migration; end +end +AddTenantToTaggings.class_eval do + def self.up + add_column :taggings, :tenant, :string, limit: 128 + add_index :taggings, :tenant unless index_exists? :taggings, :tenant + end + + def self.down + remove_index :taggings, :tenant + remove_column :taggings, :tenant + end +end diff --git a/db/migrate/20211126113845_add_category_to_activity.rb b/db/migrate/20211126113845_add_category_to_activity.rb new file mode 100644 index 0000000..692bc03 --- /dev/null +++ b/db/migrate/20211126113845_add_category_to_activity.rb @@ -0,0 +1,5 @@ +class AddCategoryToActivity < ActiveRecord::Migration[6.0] + def change + add_column :activities, :category, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 70dab44..50c3607 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_25_140327) do +ActiveRecord::Schema.define(version: 2021_11_26_113845) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -49,6 +49,7 @@ t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "description" + t.string "category" t.index ["owner_id"], name: "index_activities_on_owner_id" end @@ -62,6 +63,35 @@ t.index ["user_id"], name: "index_bookings_on_user_id" end + create_table "taggings", id: :serial, force: :cascade do |t| + t.integer "tag_id" + t.string "taggable_type" + t.integer "taggable_id" + t.string "tagger_type" + t.integer "tagger_id" + t.string "context", limit: 128 + t.datetime "created_at" + t.string "tenant", limit: 128 + t.index ["context"], name: "index_taggings_on_context" + t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true + t.index ["tag_id"], name: "index_taggings_on_tag_id" + t.index ["taggable_id", "taggable_type", "context"], name: "taggings_taggable_context_idx" + t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy" + t.index ["taggable_id"], name: "index_taggings_on_taggable_id" + t.index ["taggable_type"], name: "index_taggings_on_taggable_type" + t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type" + t.index ["tagger_id"], name: "index_taggings_on_tagger_id" + t.index ["tenant"], name: "index_taggings_on_tenant" + end + + create_table "tags", id: :serial, force: :cascade do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "taggings_count", default: 0 + t.index ["name"], name: "index_tags_on_name", unique: true + end + create_table "travels", force: :cascade do |t| t.string "country" t.string "city" @@ -100,5 +130,6 @@ add_foreign_key "activities", "users", column: "owner_id" add_foreign_key "bookings", "activities" add_foreign_key "bookings", "users" + add_foreign_key "taggings", "tags" add_foreign_key "travels", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index 1303467..86ada36 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -40,6 +40,7 @@ [user1, user2, user3, user4, user5, user6, user7, user8].each do |attributes| user = User.new(attributes) user.photo.attach(io: URI.open(attributes[:photo]), filename: "#{user.first_name}#{user.last_name}.png", content_type: "image/jpg") + user.hobby_list.add(["Sports", "Nature", "Visiting", "Food", "Bars", "Tech", "Arts", "Crafts", "Dancing", "Singing", "Shopping"].sample(8)) user.save puts "Created #{user.first_name}" end @@ -64,6 +65,7 @@ ) user.email = "#{user.first_name}.#{user.last_name}@gmail.com" user.photo.attach(io: URI.open("https://randomuser.me/api/portraits/men/#{picture_id}.jpg"), filename: "#{user.first_name}#{user.last_name}.png", content_type: "image/jpg") + user.hobby_list.add(["Sports", "Nature", "Visiting", "Food", "Bars", "Tech", "Arts", "Crafts", "Dancing", "Singing", "Shopping"].sample(8)) user.save picture_id += 1 puts "Created #{user.first_name} 🧑‍🦱" @@ -88,6 +90,7 @@ ) user.email = "#{user.first_name}.#{user.last_name}@gmail.com" user.photo.attach(io: URI.open("https://randomuser.me/api/portraits/men/#{picture_id_woman}.jpg"), filename: "#{user.first_name}#{user.last_name}.png", content_type: "image/jpg") + user.hobby_list.add(["Sports", "Nature", "Visiting", "Food", "Bars", "Tech", "Arts", "Crafts", "Dancing", "Singing", "Shopping"].sample(8)) user.save picture_id += 1 puts "Created #{user.first_name} 👩‍🦰" @@ -96,30 +99,32 @@ puts "Creating activities... THE ANSWER IS... ‼️ wait 10 more seconds..." -activity1 = { name: "Visiting Sintra", place: "Sintra, Lisbon, Portugal", description: "Let's go on a day trip to Sintra to visit the Palaces. Who wants to join ? :)", owner_id: User.find_by_first_name('Amelie').id, capacity_max: "10", start_date: DateTime.new(2021,12,1,17), end_date: DateTime.new(2021,12,2,17), photo: "https://images.unsplash.com/photo-1562195168-c82fea0f0953?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8c2ludHJhfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=800&q=60" } +activity1 = { name: "Visiting Sintra", category: "Visiting", place: "Sintra, Lisbon, Portugal", description: "Let's go on a day trip to Sintra to visit the Palaces. Who wants to join ? :)", owner_id: User.find_by_first_name('Amelie').id, capacity_max: "10", start_date: DateTime.new(2021,11,26,17), end_date: DateTime.new(2021,11,26,17), photo: "https://images.unsplash.com/photo-1562195168-c82fea0f0953?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8c2ludHJhfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=800&q=60" } -activity2 = { name: "The pastry tour : tasting typical Lisbon egg tarts in Alfama", place: "Alfama, Lisbon, Portugal", description: "If you too love pastries, join me on a tour of all the pastries in Alfama. The goal is to taste the best pasteis de nata to choose our favorite. Ready ?", owner_id: User.find_by_first_name('Amelie').id, capacity_max: "8", start_date: DateTime.new(2021,11,29,11), end_date: DateTime.new(2021,11,29,13), photo: "https://media.istockphoto.com/photos/portugal-egg-tart-with-azulejo-picture-id1124635330?b=1&k=20&m=1124635330&s=170667a&w=0&h=PbHCGQhL-kaB7Q8Ya1TXKrWe6uOLRE5woiAmSUWdbpU=" } +activity2 = { name: "The pastry tour : tasting typical Lisbon egg tarts in Alfama", category: "Food", place: "Alfama, Lisbon, Portugal", description: "If you too love pastries, join me on a tour of all the pastries in Alfama. The goal is to taste the best pasteis de nata to choose our favorite. Ready ?", owner_id: User.find_by_first_name('Amelie').id, capacity_max: "8", start_date: DateTime.new(2021,11,29,11), end_date: DateTime.new(2021,11,29,13), photo: "https://media.istockphoto.com/photos/portugal-egg-tart-with-azulejo-picture-id1124635330?b=1&k=20&m=1124635330&s=170667a&w=0&h=PbHCGQhL-kaB7Q8Ya1TXKrWe6uOLRE5woiAmSUWdbpU=" } -activity3 = { name: "Learning Fado with Lourenço and Carla - singing lesson", place: "Chiado, Lisbon, Portugal", description: "For music and singing lovers, I suggest you join me for a great Fado course for beginners with artists Lourenço and Carla. I met them during my last stay in Lisbon and promised myself to discover Fado with them on my next stay. There are only six spots for this session so don't wait to register!", owner_id: User.find_by_first_name('Jason').id, capacity_max: "30", start_date: DateTime.new(2021,12,3,14), end_date: DateTime.new(2021,12,3,17), photo: "https://media.istockphoto.com/photos/band-performing-traditional-music-fado-under-pergola-with-azulejos-in-picture-id1064650996?b=1&k=20&m=1064650996&s=170667a&w=0&h=GH90-V2xVAO_cTwgFSeZWc_mICTH8WCAT7eivprukKY=" } +activity3 = { name: "Learning Fado with Lourenço and Carla - singing lesson", category: "Singing", place: "Chiado, Lisbon, Portugal", description: "For music and singing lovers, I suggest you join me for a great Fado course for beginners with artists Lourenço and Carla. I met them during my last stay in Lisbon and promised myself to discover Fado with them on my next stay. There are only six spots for this session so don't wait to register!", owner_id: User.find_by_first_name('Jason').id, capacity_max: "30", start_date: DateTime.new(2021,11,26,14), end_date: DateTime.new(2021,11,26,17), photo: "https://media.istockphoto.com/photos/band-performing-traditional-music-fado-under-pergola-with-azulejos-in-picture-id1064650996?b=1&k=20&m=1064650996&s=170667a&w=0&h=GH90-V2xVAO_cTwgFSeZWc_mICTH8WCAT7eivprukKY=" } -activity4 = { name: "Cooking class with Bruna", place: "Belém, Lisbon, Portugal", description: "An event not to be missed! I suggest you come with me for a cooking class with chef Bruna in the heart of the Bélem district. We will learn to cook nine typical dishes that we will then share during a dinner accompanied by good local wines. The class takes place in Bruna's restaurant. Here is the list of dishes that we will learn to cook: Bacalhau com Natas, Arroz de Marisco, Dourada Grelhada, Bacalhau in Brás, Bife a Café, Carne by Porco Alentejana, Sardinhas Assadas, Arroz de Pato, Arroz de Tamboril.", owner_id: User.find_by_first_name('Karim').id, capacity_max: "4", start_date: DateTime.new(2021,12,1,9), end_date: DateTime.new(2021,12,1,15), photo: "https://images.unsplash.com/photo-1549590143-d5855148a9d5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8Y29va2luZ3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } +activity4 = { name: "Cooking class with Bruna", category: "Food", place: "Belém, Lisbon, Portugal", description: "An event not to be missed! I suggest you come with me for a cooking class with chef Bruna in the heart of the Bélem district. We will learn to cook nine typical dishes that we will then share during a dinner accompanied by good local wines. The class takes place in Bruna's restaurant. Here is the list of dishes that we will learn to cook: Bacalhau com Natas, Arroz de Marisco, Dourada Grelhada, Bacalhau in Brás, Bife a Café, Carne by Porco Alentejana, Sardinhas Assadas, Arroz de Pato, Arroz de Tamboril.", owner_id: User.find_by_first_name('Jason').id, capacity_max: "4", start_date: DateTime.new(2021,12,1,9), end_date: DateTime.new(2021,12,1,15), photo: "https://images.unsplash.com/photo-1549590143-d5855148a9d5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8Y29va2luZ3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } -activity5 = { name: "Networking event for tech people in Bairro Alto", place: "Bairro Alto, Lisbon, Portugal", description: "With my amazing workmates at Softbank,Tokyo, we organize a dev&tech gathering in a bar in Bairro Alto this saturday night. Come join us for a crazy night out !", owner_id: User.find_by_first_name('Caroline').id, capacity_max: "30", start_date: DateTime.new(2021,11,30,20), end_date: DateTime.new(2021,12,1,2), photo: "https://media.istockphoto.com/photos/casual-catering-discussion-meeting-colleagues-concept-picture-id597940046?b=1&k=20&m=597940046&s=170667a&w=0&h=GSqvi2bfqWORR4PUTkzh4j1AcXK3katN4ml5MpkqnWo=" } +activity5 = { name: "Networking event for tech people in Bairro Alto", category: "Tech", place: "Bairro Alto, Lisbon, Portugal", description: "With my amazing workmates at Softbank,Tokyo, we organize a dev&tech gathering in a bar in Bairro Alto this saturday night. Come join us for a crazy night out !", owner_id: User.find_by_first_name('Caroline').id, capacity_max: "30", start_date: DateTime.new(2021,11,30,20), end_date: DateTime.new(2021,12,1,2), photo: "https://media.istockphoto.com/photos/casual-catering-discussion-meeting-colleagues-concept-picture-id597940046?b=1&k=20&m=597940046&s=170667a&w=0&h=GSqvi2bfqWORR4PUTkzh4j1AcXK3katN4ml5MpkqnWo=" } -activity6 = { name: "Visiting Nara : culture and history", place: "Nara, Japan", description: "Come visit Nara with me this weekend !", owner_id: User.find_by_first_name('Yasmine').id, capacity_max: "40", start_date: DateTime.new(2021,12,2,9), end_date: DateTime.new(2021,12,2,21), photo: "https://images.unsplash.com/photo-1537153725174-cba5e5e81ab0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8bmFyYXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } +activity6 = { name: "Visiting Nara : culture and history", category: "Visiting", place: "Nara, Japan", description: "Come visit Nara with me this weekend !", owner_id: User.find_by_first_name('Yasmine').id, capacity_max: "40", start_date: DateTime.new(2021,12,2,9), end_date: DateTime.new(2021,12,2,21), photo: "https://images.unsplash.com/photo-1537153725174-cba5e5e81ab0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8bmFyYXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } -activity7 = { name: "Crazy night in Shibuya : bars !", place: "Shibuya, Tokyo, Japan", description: "Let's paint the town red. Our challenge tonight ? Have a drink in every bar at Shibuya.", owner_id: User.find_by_first_name('Yasmine').id, capacity_max: "10", start_date: DateTime.new(2021,12,1,18), end_date: DateTime.new(2021,12,2,7), photo: "https://images.unsplash.com/photo-1542052125323-e69ad37a47c2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8c2hpYnV5YXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } +activity7 = { name: "Crazy night in Shibuya : bars !", category: "Bars", place: "Shibuya, Tokyo, Japan", description: "Let's paint the town red. Our challenge tonight ? Have a drink in every bar at Shibuya.", owner_id: User.find_by_first_name('Yasmine').id, capacity_max: "10", start_date: DateTime.new(2021,12,1,18), end_date: DateTime.new(2021,12,2,7), photo: "https://images.unsplash.com/photo-1542052125323-e69ad37a47c2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8c2hpYnV5YXxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } -activity8 = { name: "Shopping in Akihabara", place: "Akihabara, Tokyo, Japan", description: "Wanna buy some brand new games, Sonic Cosplays, gadgets ? Let's go to Akihabara on sunday :):)", owner_id: User.find_by_first_name('Sam').id, capacity_max: "5", start_date: DateTime.new(2021,12,1,15), end_date: DateTime.new(2021,12,1,19), photo: "https://media.istockphoto.com/photos/akihabara-tokyo-japan-picture-id468356740?b=1&k=20&m=468356740&s=170667a&w=0&h=kLkcA2hevgkassPl_1rWOPbRpLaZuzarV7KHlD3LH2g=" } +activity8 = { name: "Shopping in Akihabara", category: "Shopping", place: "Akihabara, Tokyo, Japan", description: "Wanna buy some brand new games, Sonic Cosplays, gadgets ? Let's go to Akihabara on sunday :):)", owner_id: User.find_by_first_name('Sam').id, capacity_max: "5", start_date: DateTime.new(2021,12,1,15), end_date: DateTime.new(2021,12,1,19), photo: "https://media.istockphoto.com/photos/akihabara-tokyo-japan-picture-id468356740?b=1&k=20&m=468356740&s=170667a&w=0&h=kLkcA2hevgkassPl_1rWOPbRpLaZuzarV7KHlD3LH2g=" } -activity9 = { name: "Samba ! Dance lessons with Ricardo and Manuela", place: "Rio de Janeiro, Brazil", description: "I love dancing and am really excited about learning the basics of Samba with Ricardo and Manuela ! I met them during Carnival and they proposed to teach me some steps. Wanna join ?", owner_id: User.find_by_first_name('Yukio').id, capacity_max: "60", start_date: DateTime.new(2021,12,2,18), end_date: DateTime.new(2021,12,2,22), photo: "https://media.istockphoto.com/photos/couple-dancers-practicing-in-studio-holding-hands-picture-id1264865152?b=1&k=20&m=1264865152&s=170667a&w=0&h=Hd2LdgDMsfhenPsHtAJuv7h4QdbW1qLrcJbQZEV06HA=" } +activity9 = { name: "Samba ! Dance lessons with Ricardo and Manuela", category: "Dancing", place: "Rio de Janeiro, Brazil", description: "I love dancing and am really excited about learning the basics of Samba with Ricardo and Manuela ! I met them during Carnival and they proposed to teach me some steps. Wanna join ?", owner_id: User.find_by_first_name('Yukio').id, capacity_max: "60", start_date: DateTime.new(2021,12,2,18), end_date: DateTime.new(2021,12,2,22), photo: "https://media.istockphoto.com/photos/couple-dancers-practicing-in-studio-holding-hands-picture-id1264865152?b=1&k=20&m=1264865152&s=170667a&w=0&h=Hd2LdgDMsfhenPsHtAJuv7h4QdbW1qLrcJbQZEV06HA=" } -activity10 = { name: "The blockchain Job Fair in Hong Kong", place: "5 Connaught Rd Central, Central, Hong Kong", description: "Are you looking for the opportunity of your dreams in Data or Blockchain technologies? This unique event is for you! Register quickly as places are limited and we will not be able to accept all registrations 👨🏼‍🎓", owner_id: User.find_by_first_name('Yukio').id, capacity_max: "100", start_date: DateTime.new(2021,12,2,8), end_date: DateTime.new(2021,12,2,18), photo: "https://media.istockphoto.com/photos/bitcoin-network-concept-on-digital-screen-picture-id1297465792?b=1&k=20&m=1297465792&s=170667a&w=0&h=w4ADFjvxsfswEwKcsX1QZNVlBaXmPyYbzF13iuUggm0=" } +activity10 = { name: "The blockchain Job Fair in Hong Kong", category: "Tech", place: "5 Connaught Rd Central, Central, Hong Kong", description: "Are you looking for the opportunity of your dreams in Data or Blockchain technologies? This unique event is for you! Register quickly as places are limited and we will not be able to accept all registrations 👨🏼‍🎓", owner_id: User.find_by_first_name('Karim').id, capacity_max: "100", start_date: DateTime.new(2021,12,2,8), end_date: DateTime.new(2021,12,2,18), photo: "https://media.istockphoto.com/photos/bitcoin-network-concept-on-digital-screen-picture-id1297465792?b=1&k=20&m=1297465792&s=170667a&w=0&h=w4ADFjvxsfswEwKcsX1QZNVlBaXmPyYbzF13iuUggm0=" } -activity11 = { name: "Giant basketball tournament in Hong Kong", place: "2 Tse Wai Ave, Ngau Chi Wan, Hong Kong", description: "For basketball fans! Come and participate in our giant basketball tournament on a legendary court overlooking the city of Hong Kong. We'll have a drink at the end of the tournament;)", owner_id: User.find_by_first_name('Karim').id, capacity_max: "40", start_date: DateTime.new(2021,12,2,16), end_date: DateTime.new(2021,12,2,22), photo: "https://images.unsplash.com/photo-1465509419584-d2b0ff1ce390?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTN8fGJhc2tldGJhbGwlMjBob25nJTIwa29uZ3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } +activity11 = { name: "Giant basketball tournament in Hong Kong", category: "Sports", place: "2 Tse Wai Ave, Ngau Chi Wan, Hong Kong", description: "For basketball fans! Come and participate in our giant basketball tournament on a legendary court overlooking the city of Hong Kong. We'll have a drink at the end of the tournament;)", owner_id: User.find_by_first_name('Karim').id, capacity_max: "40", start_date: DateTime.new(2021,12,2,16), end_date: DateTime.new(2021,12,2,22), photo: "https://images.unsplash.com/photo-1465509419584-d2b0ff1ce390?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTN8fGJhc2tldGJhbGwlMjBob25nJTIwa29uZ3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60" } +activity12 = { name: "Ping Pong", category: "Sports", place: "Campo dos Mártires da Pátria, Lisbon", description: "Don't miss this crazy event for ping pong lovers ! If you like to ping, if you like to pong. Be there !", owner_id: User.find_by_first_name('Caroline').id, capacity_max: "20", start_date: DateTime.new(2021,11,26,16), end_date: DateTime.new(2021,11,26,22), photo: "https://images.unsplash.com/photo-1593786481097-cf281dd12e9e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGluZyUyMHBvbmd8ZW58MHx8MHx8&auto=format&fit=crop&w=800&q=60" } -[activity1, activity2, activity3, activity4, activity5, activity6, activity7, activity8, activity9, activity10, activity11].each_with_index do |attributes, index| + +[activity1, activity2, activity3, activity4, activity5, activity6, activity7, activity8, activity9, activity10, activity11, activity12].each_with_index do |attributes, index| activity = Activity.new(attributes) activity.photo.attach(io: URI.open(attributes[:photo]), filename: "#{activity.owner_id}_#{index}.jpg", content_type: "image/jpg") activity.save