Added Submission model
This commit is contained in:
parent
5ca234c8fc
commit
933e14673c
9 changed files with 49 additions and 31 deletions
|
|
@ -3,11 +3,10 @@ class SurveyController < ApplicationController
|
|||
load_and_authorize_resource
|
||||
|
||||
def show
|
||||
|
||||
@survey_submission = @survey.survey_submissions.new
|
||||
end
|
||||
|
||||
def reply
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
7
app/models/survey_submission.rb
Normal file
7
app/models/survey_submission.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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) }
|
||||
|
|
|
|||
|
|
@ -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}" }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
10
db/migrate/20160630130731_create_survey_submissions.rb
Normal file
10
db/migrate/20160630130731_create_survey_submissions.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue