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
|
load_and_authorize_resource
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@survey_submission = @survey.survey_submissions.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply
|
def reply
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
class Survey < ActiveRecord::Base
|
class Survey < ActiveRecord::Base
|
||||||
belongs_to :surveyable, polymorphic: true
|
belongs_to :surveyable, polymorphic: true
|
||||||
has_many :survey_questions
|
has_many :survey_questions
|
||||||
|
has_many :survey_submissions
|
||||||
|
|
||||||
enum target: [:after_conference, :during_registration]
|
enum target: [:after_conference, :during_registration]
|
||||||
validates :title, presence: true
|
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 :voted_events, through: :votes, source: :events
|
||||||
has_many :subscriptions, dependent: :destroy
|
has_many :subscriptions, dependent: :destroy
|
||||||
has_many :survey_replies
|
has_many :survey_replies
|
||||||
|
has_many :survey_submissions
|
||||||
accepts_nested_attributes_for :roles
|
accepts_nested_attributes_for :roles
|
||||||
|
|
||||||
scope :admin, -> { where(is_admin: true) }
|
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
|
= 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
|
%span.fa.fa-times
|
||||||
.panel-body
|
.panel-body
|
||||||
- if survey_question.boolean?
|
= f.semantic_fields_for :survey_reply do |reply, index|
|
||||||
= f.input "survey_question_#{survey_question.id}", as: :radio, name: 'Yes'
|
= reply.hidden_field :survey_question_id, value: survey_question.id
|
||||||
%br
|
- if survey_question.boolean?
|
||||||
= f.input "survey_question_#{survey_question.id}", as: :radio, name: 'No'
|
= reply.input :text, as: :radio, label: false
|
||||||
- elsif survey_question.choice?
|
- elsif survey_question.choice?
|
||||||
- survey_question.possible_answers.split(',').map(&:strip).each do |option|
|
- choice_type = survey_question.single_choice? ? :radio : :check_boxes
|
||||||
- if survey_question.single_choice?
|
= reply.input :text, as: choice_type, label: false, collection: survey_question.possible_answers.split(',').map(&:strip)
|
||||||
%input{ type: 'radio', name: "survey_question_#{survey_question.id}" }
|
- elsif survey_question.string?
|
||||||
= option
|
%input.form-control{ name: "survey_question_#{survey_question.id}" }
|
||||||
%br
|
- elsif survey_question.text?
|
||||||
- else
|
%textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" }
|
||||||
%input{ type: 'checkbox', name: "survey_question_#{survey_question.id}" }
|
- elsif survey_question.datetime?
|
||||||
= option
|
.form-group{ class: 'datetimepicker' }
|
||||||
%br
|
.input-group
|
||||||
- elsif survey_question.string?
|
.input-group-addon
|
||||||
%input.form-control{ name: "survey_question_#{survey_question.id}" }
|
%span.fa.fa-calendar
|
||||||
- elsif survey_question.text?
|
%input.form-control{ readonly: 'readonly', name: "survey_question_#{survey_question.id}" }
|
||||||
%textarea.form-control{ rows: 4, name: "survey_question_#{survey_question.id}" }
|
- elsif survey_question.numeric?
|
||||||
- elsif survey_question.datetime?
|
%input.form-control{ type: 'number', name: "survey_question_#{survey_question.id}" }
|
||||||
.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
|
.row
|
||||||
.col-md-12
|
.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|
|
- @survey.survey_questions.each.with_index(1) do |survey_question, index|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ Osem::Application.routes.draw do
|
||||||
|
|
||||||
resources :conference, only: [:index, :show] do
|
resources :conference, only: [:index, :show] do
|
||||||
resources :survey, only: [:show] do
|
resources :survey, only: [:show] do
|
||||||
patch :reply
|
post :reply
|
||||||
end
|
end
|
||||||
resource :program, only: [] do
|
resource :program, only: [] do
|
||||||
resources :proposal, except: :destroy 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.
|
# 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|
|
create_table "ahoy_events", force: :cascade do |t|
|
||||||
t.uuid "visit_id", limit: 16
|
t.uuid "visit_id", limit: 16
|
||||||
|
|
@ -393,6 +393,13 @@ ActiveRecord::Schema.define(version: 20160630094850) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
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|
|
create_table "surveys", force: :cascade do |t|
|
||||||
t.datetime "start_date"
|
t.datetime "start_date"
|
||||||
t.datetime "end_date"
|
t.datetime "end_date"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue