forked from bofh/fetsite
AutoCommit Don Jul 30 01:03:05 CEST 2015
This commit is contained in:
@@ -10,6 +10,10 @@ class Survey::QuestionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
def answer
|
||||
@survey_question = Survey::Question.find(params[:id])
|
||||
|
||||
|
||||
@survey_question.do_answer(params[:survey_question][:selected],current_user)
|
||||
render :show
|
||||
end
|
||||
# GET /survey/questions/1
|
||||
|
||||
@@ -2,4 +2,7 @@ class Survey::Choice < ActiveRecord::Base
|
||||
belongs_to :question, class_name: 'Survey::Question'
|
||||
attr_accessible :picture, :sort, :text
|
||||
has_many :answers, class_name: 'Survey::Answer'
|
||||
def to_s
|
||||
self.text
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,16 @@ class Survey::Question < ActiveRecord::Base
|
||||
c=Survey::Choice.new(title: "Nein")
|
||||
c.save
|
||||
this.choices << c
|
||||
end
|
||||
|
||||
def do_answer(choice_ids, user)
|
||||
self.answers.where(user_id: user.id).each {|a| a.delete}
|
||||
choice_ids.each do |c|
|
||||
if self.choice_ids.include?(c)
|
||||
a=Survey::Answer.new(user_id: user.id, choice_id: c)
|
||||
a.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
4
app/views/survey/questions/_answeredquestion.html.erb
Normal file
4
app/views/survey/questions/_answeredquestion.html.erb
Normal file
@@ -0,0 +1,4 @@
|
||||
<div style="background:red"><b><%= answeredquestion.title%></b>
|
||||
<% answeredquestion.choices.each do |c| %>
|
||||
<%= c.to_s %><%= answeredquestion.answers.where(choice_id: c.id).count %>
|
||||
<% end %>
|
||||
@@ -1,2 +1,8 @@
|
||||
<b><%= question.title%></b>
|
||||
<%= form_for %>
|
||||
<div style="background:red"><b><%= question.title%></b>
|
||||
<%= semantic_form_for question, url: answer_survey_question_path do |f| %>
|
||||
<%= f.input :selected, as: :check_boxes, collection: question.choices %>
|
||||
<%= f.actions do %>
|
||||
<%= f.action :submit, :as => :input %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
</p>
|
||||
|
||||
<%= render @survey_question %>
|
||||
<%= render partial: "answeredquestion", object: @survey_question %>
|
||||
|
||||
<%= link_to 'Edit', edit_survey_question_path(@survey_question) %> |
|
||||
<%= link_to 'Back', survey_questions_path %>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace :survey do
|
||||
resources :questions do
|
||||
member do
|
||||
:answer
|
||||
put :answer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user