Skip to content

Commit

Permalink
Add titles
Browse files Browse the repository at this point in the history
  • Loading branch information
iHiD committed Jan 9, 2025
1 parent c778562 commit 7a21868
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/helpers/react_components/bootcamp/drawing_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def id = "bootcamp-drawing-page"
def data
{
drawing: {
uuid: drawing.uuid
uuid: drawing.uuid,
title: drawing.title
},
code: {
code: drawing.code,
Expand Down
1 change: 1 addition & 0 deletions app/models/bootcamp/drawing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Bootcamp::Drawing < ApplicationRecord
before_create do
self.uuid = SecureRandom.uuid unless uuid.present?
self.code = "" unless code.present?
self.title = "Drawing #{user.bootcamp_drawings.count + 1}" unless title.present?
end

def to_param = uuid
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20250109143039_add_title_to_drawings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AddTitleToDrawings < ActiveRecord::Migration[7.0]
def change
return if Rails.env.production?

add_column :bootcamp_drawings, :title, :string, null: true

Bootcamp::Drawing.all.each do |drawing|
drawing.update!(title: "Drawing #{drawing.id}")
end

change_column_null :bootcamp_drawings, :title, false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2025_01_08_193404) do
ActiveRecord::Schema[7.0].define(version: 2025_01_09_143039) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down Expand Up @@ -90,6 +90,7 @@
t.text "code", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title", null: false
t.index ["user_id"], name: "index_bootcamp_drawings_on_user_id"
end

Expand Down

0 comments on commit 7a21868

Please sign in to comment.