Fix install of taggable gem and add tags to seeds

This commit is contained in:
Manuel Bustillo 2024-07-11 20:41:07 +02:00
parent c0ed5a68c3
commit 3660d14d44
7 changed files with 38 additions and 2 deletions

View File

@ -49,6 +49,7 @@ group :development, :test do
gem "debug", platforms: %i[ mri windows ]
gem 'rspec-rails', '~> 6.1.0'
gem 'faker'
gem 'pry'
end
group :development do

View File

@ -83,6 +83,7 @@ GEM
bootsnap (1.18.3)
msgpack (~> 1.2)
builder (3.3.0)
coderay (1.1.3)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crass (1.0.6)
@ -119,6 +120,7 @@ GEM
net-pop
net-smtp
marcel (1.0.4)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.24.1)
money (6.16.0)
@ -148,6 +150,9 @@ GEM
nokogiri (1.16.6-x86_64-linux)
racc (~> 1.4)
pg (1.5.6)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.1.2)
stringio
puma (6.4.2)
@ -262,6 +267,7 @@ DEPENDENCIES
jbuilder
money
pg (~> 1.1)
pry
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.2)
redis (>= 4.0.1)

View File

@ -1,4 +1,6 @@
class Guest < ApplicationRecord
acts_as_taggable_on :affinity_groups, :unbreakable_bonds
def full_name
"#{first_name} #{last_name}"
end

View File

@ -9,6 +9,7 @@
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Affinity groups</th>
<th colspan="2"></th>
</tr>
<% @guests.each_with_index do |guest, i| %>
@ -17,6 +18,7 @@
<td><%= guest.full_name %></td>
<td><%= guest.email %></td>
<td><%= guest.phone %></td>
<td><%= guest.affinity_group_list %></td>
<td><%= link_to "Show", guest %></td>
<td><%= link_to "Edit", edit_guest_path(guest) %></td>
</tr>

View File

@ -13,7 +13,7 @@ class ActsAsTaggableOnMigration < ActiveRecord::Migration[6.0]
# You should make sure that the column created is
# long enough to store the required class names.
t.references :taggable, polymorphic: true
t.references :taggable, polymorphic: true, type: :uuid
t.references :tagger, polymorphic: true
# Limit is created to prevent MySQL error on index

2
db/schema.rb generated
View File

@ -38,7 +38,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_11_181632) do
create_table "taggings", force: :cascade do |t|
t.bigint "tag_id"
t.string "taggable_type"
t.bigint "taggable_id"
t.uuid "taggable_id"
t.string "tagger_type"
t.bigint "tagger_id"
t.string "context", limit: 128

View File

@ -10,6 +10,8 @@
Expense.delete_all
Guest.delete_all
ActsAsTaggableOn::Tagging.delete_all
ActsAsTaggableOn::Tag.delete_all
Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed')
Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed')
@ -32,3 +34,26 @@ Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
email: Faker::Internet.email,
phone: Faker::PhoneNumber.cell_phone)
end
{
close_family: 10,
family_1_group_a: 5,
family_1_group_b: 5,
family_2_group_a: 7,
family_2_group_b: 15,
previous_company: 5,
new_company: 15,
college: 10,
high_school: 5,
childhood: 5,
basket_team: 20,
soccer_team: 15,
dance_club: 10
}.each do |affinity_group, count|
Guest.all.sample(count).each do |guest|
guest.affinity_group_list.add(affinity_group)
guest.save!
rescue => e
binding.pry
end
end