diff --git a/app/controllers/admin/surveys_controller.rb b/app/controllers/admin/surveys_controller.rb index 4e99a96d..fe17a51a 100644 --- a/app/controllers/admin/surveys_controller.rb +++ b/app/controllers/admin/surveys_controller.rb @@ -40,7 +40,7 @@ module Admin private def survey_params - params.require(:survey).permit(:title, :description, :start_date, :end_date, :surveyable_type, :surveyable_id) + params.require(:survey).permit(:title, :description, :target, :start_date, :end_date, :surveyable_type, :surveyable_id) end end end diff --git a/app/models/survey_question.rb b/app/models/survey_question.rb index 1b10fdb7..a5718333 100644 --- a/app/models/survey_question.rb +++ b/app/models/survey_question.rb @@ -12,6 +12,8 @@ class SurveyQuestion < ActiveRecord::Base validates :max_choices, numericality: { greater_than_or_equal_to: 1 }, allow_blank: true validate :max_choices_greater_than_min + has_many :survey_replies + def single_choice? choice? && max_choices == 1 && min_choices == 1 diff --git a/app/models/survey_reply.rb b/app/models/survey_reply.rb new file mode 100644 index 00000000..67edbc84 --- /dev/null +++ b/app/models/survey_reply.rb @@ -0,0 +1,5 @@ +class SurveyReply < ActiveRecord::Base + belongs_to :user + belongs_to :survey_question + serialize :text +end diff --git a/app/models/user.rb b/app/models/user.rb index d3c847a2..4bd2d3da 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -42,6 +42,7 @@ class User < ActiveRecord::Base has_many :votes, dependent: :destroy has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy + has_many :survey_replies accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } diff --git a/db/migrate/20160630094850_create_survey_replies.rb b/db/migrate/20160630094850_create_survey_replies.rb new file mode 100644 index 00000000..3b8917de --- /dev/null +++ b/db/migrate/20160630094850_create_survey_replies.rb @@ -0,0 +1,11 @@ +class CreateSurveyReplies < ActiveRecord::Migration + def change + create_table :survey_replies do |t| + t.integer :survey_question_id + t.integer :user_id + t.text :text + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index da777c4f..597c4fce 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: 20160629145954) do +ActiveRecord::Schema.define(version: 20160630094850) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -385,6 +385,14 @@ ActiveRecord::Schema.define(version: 20160629145954) do t.boolean "mandatory", default: false end + create_table "survey_replies", force: :cascade do |t| + t.integer "survey_question_id" + t.integer "user_id" + t.text "text" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "surveys", force: :cascade do |t| t.datetime "start_date" t.datetime "end_date"