diff --git a/app/models/question_format.rb b/app/models/question_format.rb index 17c3123..3a08be8 100644 --- a/app/models/question_format.rb +++ b/app/models/question_format.rb @@ -1,9 +1,11 @@ class QuestionFormat < ActiveRecord::Base - include FlagShihTzu ## # Associations has_many :questions + + enum formattype: [ :textarea, :textfield, :radiobuttons, :checkbox, :dropdown, :multiselectbox, :date ] + attr_accessible :formattype validates :title, presence: true, uniqueness: true @@ -15,14 +17,6 @@ ## # Define Bit Field Values so we can test a format without doing string comps # Column type - has_flags 1 => :textarea, - 2 => :textfield, - 3 => :radiobuttons, - 4 => :checkbox, - 5 => :dropdown, - 6 => :multiselectbox, - 7 => :date, - column: 'formattype' # EVALUATE CLASS AND INSTANCE METHODS BELOW # diff --git a/db/migrate/20170302111544_question_format_to_enum.rb b/db/migrate/20170302111544_question_format_to_enum.rb new file mode 100644 index 0000000..45624e2 --- /dev/null +++ b/db/migrate/20170302111544_question_format_to_enum.rb @@ -0,0 +1,32 @@ +class QuestionFormatToEnum < ActiveRecord::Migration + def self.up + QuestionFormat.all.each do |qf| + if qf.title == "Text area" + qf.textarea! + end + if qf.title == "Text field" + qf.textfield! + end + if qf.title == "Radio buttons" + qf.radiobuttons! + end + if qf.title == "Check box" + qf.checkbox! + end + if qf.title == "Dropdown" + qf.dropdown! + end + if qf.title == "Multi select box" + qf.multiselectbox! + end + if qf.title == "Date" + qf.date! + end + qf.save + end + end + + def self.down + remove_column :question_formats, :formattype + end +end diff --git a/db/schema.rb b/db/schema.rb index 3a9bc2d..f684e9f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170301105806) do +ActiveRecord::Schema.define(version: 20170302111544) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"