diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index fa8aa75..6133a45 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -3,23 +3,10 @@ after_action :verify_authorized - TEXTAREA = QuestionFormat.where(title: "Text area").first.id - TEXTFIELD = QuestionFormat.where(title: "Text field").first.id - RADIO = QuestionFormat.where(title: "Radio buttons").first.id - CHECKBOX = QuestionFormat.where(title: "Check box").first.id - DROPDOWN = QuestionFormat.where(title: "Dropdown").first.id - MULTI = QuestionFormat.where(title: "Multi select box").first.id # GET /plans/PLANID/phases/PHASEID/edit def edit - @textarea = TEXTAREA - @textfield = TEXTFIELD - @radio = RADIO - @checkbox = CHECKBOX - @dropdown = DROPDOWN - @multi = MULTI - @plan = Plan.find(params[:plan_id]) authorize @plan diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index edae8f5..43be23d 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -6,12 +6,6 @@ before_filter :get_plan_list_columns, only: %i( index ) after_action :verify_authorized - TEXTAREA = QuestionFormat.where(title: "Text area").first.id - TEXTFIELD = QuestionFormat.where(title: "Text field").first.id - RADIO = QuestionFormat.where(title: "Radio buttons").first.id - CHECKBOX = QuestionFormat.where(title: "Check box").first.id - DROPDOWN = QuestionFormat.where(title: "Dropdown").first.id - MULTI = QuestionFormat.where(title: "Multi select box").first.id def index authorize Plan @@ -148,12 +142,6 @@ # # GET /plans/1/edit def edit - @textarea = TEXTAREA - @textfield = TEXTFIELD - @radio = RADIO - @checkbox = CHECKBOX - @dropdown = DROPDOWN - @multi = MULTI @plan = Plan.find(params[:id]) 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"