-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from portabilis/fix-label-problem
Corrige problema relacionado a Label
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |