Skip to content

Commit

Permalink
Merge pull request #97 from portabilis/fix-label-problem
Browse files Browse the repository at this point in the history
Corrige problema relacionado a Label
  • Loading branch information
gustavomendess authored Apr 1, 2022
2 parents aa47599 + 917f537 commit 16b3e0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/label.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Label < ActiveRecord::Base
COLORS = %w(#9121AD #AD2121 #AD6421 #C9AC13 #21AD27 #21A5AD #212FAD #BC62D2 #D26262 #C88F5A #D8BC59 #5AB8CD
#5AB8CD #6274D2 #7A7A7A)

belongs_to :labelable, polymorphic: true

before_create :set_color

private

def set_color
self.color = COLORS.sample
end
end
13 changes: 13 additions & 0 deletions db/migrate/20200517213022_create_labels.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateLabels < ActiveRecord::Migration
def change
create_table :labels do |t|
t.string :name
t.string :labelable_type
t.integer :labelable_id

t.timestamps null: false
end

add_index :labels, [:labelable_type, :labelable_id]
end
end

0 comments on commit 16b3e0b

Please sign in to comment.