Add survey replies.

This commit is contained in:
Shyukri Shyukriev 2016-06-30 12:05:00 +02:00
parent 03168b4efe
commit 157a16d8f2
6 changed files with 29 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,5 @@
class SurveyReply < ActiveRecord::Base
belongs_to :user
belongs_to :survey_question
serialize :text
end

View file

@ -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) }