diff --git a/app/controllers/survey_controller.rb b/app/controllers/survey_controller.rb index f22a4fb3..e4d21f8b 100644 --- a/app/controllers/survey_controller.rb +++ b/app/controllers/survey_controller.rb @@ -3,11 +3,10 @@ class SurveyController < ApplicationController load_and_authorize_resource def show - + @survey_submission = @survey.survey_submissions.new end def reply - end end diff --git a/app/models/survey.rb b/app/models/survey.rb index ac3e04a4..a98968a7 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -1,6 +1,7 @@ class Survey < ActiveRecord::Base belongs_to :surveyable, polymorphic: true has_many :survey_questions + has_many :survey_submissions enum target: [:after_conference, :during_registration] validates :title, presence: true diff --git a/app/models/survey_submission.rb b/app/models/survey_submission.rb new file mode 100644 index 00000000..af8291b1 --- /dev/null +++ b/app/models/survey_submission.rb @@ -0,0 +1,7 @@ +class SurveySubmission < ActiveRecord::Base + belongs_to :user + belongs_to :survey + has_many :survey_replies, through: :user + + accepts_nested_attributes_for :survey_replies +end diff --git a/app/models/user.rb b/app/models/user.rb index 4bd2d3da..7f1ae5ef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,6 +43,7 @@ class User < ActiveRecord::Base has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy has_many :survey_replies + has_many :survey_submissions accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } diff --git a/app/views/admin/surveys/_survey_question.html.haml b/app/views/admin/surveys/_survey_question.html.haml index f1ab664e..039c2ee5 100644 --- a/app/views/admin/surveys/_survey_question.html.haml +++ b/app/views/admin/surveys/_survey_question.html.haml @@ -21,29 +21,22 @@ = link_to admin_conference_survey_survey_question_path(@conference.short_title, @survey, survey_question), method: :delete, data: { confirm: 'Are you sure you want to delete this question?' } do %span.fa.fa-times .panel-body - - if survey_question.boolean? - = f.input "survey_question_#{survey_question.id}", as: :radio, name: 'Yes' - %br - = f.input "survey_question_#{survey_question.id}", as: :radio, name: 'No' - - elsif survey_question.choice? - - survey_question.possible_answers.split(',').map(&:strip).each do |option| - - if survey_question.single_choice? - %input{ type: 'radio', name: "survey_question_#{survey_question.id}" } - = option - %br - - else - %input{ type: 'checkbox', name: "survey_question_#{survey_question.id}" } - = option - %br - - elsif survey_question.string? - %input.form-control{ name: "survey_question_#{survey_question.id}" } - - elsif survey_question.text? - %textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" } - - elsif survey_question.datetime? - .form-group{ class: 'datetimepicker' } - .input-group - .input-group-addon - %span.fa.fa-calendar - %input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" } - - elsif survey_question.numeric? - %input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" } + = f.semantic_fields_for :survey_reply do |reply, index| + = reply.hidden_field :survey_question_id, value: survey_question.id + - if survey_question.boolean? + = reply.input :text, as: :radio, label: false + - elsif survey_question.choice? + - choice_type = survey_question.single_choice? ? :radio : :check_boxes + = reply.input :text, as: choice_type, label: false, collection: survey_question.possible_answers.split(',').map(&:strip) + - elsif survey_question.string? + %input.form-control{ name: "survey_question_#{survey_question.id}" } + - elsif survey_question.text? + %textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" } + - elsif survey_question.datetime? + .form-group{ class: 'datetimepicker' } + .input-group + .input-group-addon + %span.fa.fa-calendar + %input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" } + - elsif survey_question.numeric? + %input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" } diff --git a/app/views/survey/show.html.haml b/app/views/survey/show.html.haml index aec00610..d6babaa8 100644 --- a/app/views/survey/show.html.haml +++ b/app/views/survey/show.html.haml @@ -13,7 +13,7 @@ .row .col-md-12 - = semantic_form_for @survey, url: conference_survey_reply_path(@conference.short_title, @survey) do |f| + = semantic_form_for @survey_submission, url: conference_survey_reply_path(@conference.short_title, @survey) do |f| - @survey.survey_questions.each.with_index(1) do |survey_question, index| .row .col-md-12 diff --git a/config/routes.rb b/config/routes.rb index 4ca8adf8..02a46547 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -97,7 +97,7 @@ Osem::Application.routes.draw do resources :conference, only: [:index, :show] do resources :survey, only: [:show] do - patch :reply + post :reply end resource :program, only: [] do resources :proposal, except: :destroy do diff --git a/db/migrate/20160630130731_create_survey_submissions.rb b/db/migrate/20160630130731_create_survey_submissions.rb new file mode 100644 index 00000000..bcab5271 --- /dev/null +++ b/db/migrate/20160630130731_create_survey_submissions.rb @@ -0,0 +1,10 @@ +class CreateSurveySubmissions < ActiveRecord::Migration + def change + create_table :survey_submissions do |t| + t.integer :user_id + t.integer :survey_id + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 597c4fce..59ef30c8 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: 20160630094850) do +ActiveRecord::Schema.define(version: 20160630130731) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -393,6 +393,13 @@ ActiveRecord::Schema.define(version: 20160630094850) do t.datetime "updated_at", null: false end + create_table "survey_submissions", force: :cascade do |t| + t.integer "user_id" + t.integer "survey_id" + 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"