Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Anonymous mostly working...

  • Loading branch information...
commit f2d1e53ead6c9c072b61d1a0018f19a3f930ef40 1 parent c4ef7cc
@mark-d-holmberg authored
View
1  app/controllers/responses_controller.rb
@@ -3,6 +3,7 @@ class ResponsesController < ApplicationController
def index
@student = User.find(params[:user_id])
authorize! :read, @student, :id => @student.id
+ @responses = Response.not_anonymous.where(:user_id => @student.id)
authorize! :index, Response, :user_id => current_user.id
end
View
7 app/controllers/take_surveys_controller.rb
@@ -12,11 +12,8 @@ def new
#SPEC: 7.1.1.2: Adding Create action
def create
params[:response].each do |question, answer|
- if params[:response][:content]
- current_user.responses.create :question_id => question, :answer_id => answer, :user_id => current_user.id, :content => content
- else
- current_user.responses.create :question_id => question, :answer_id => answer, :user_id => current_user.id
- end
+ current_user.responses.create :question_id => question, :answer_id => answer[:answer_id], :content => answer[:content],
+ :user_id => current_user.id
end
if current_user.save
View
2  app/models/question.rb
@@ -26,6 +26,8 @@ class Question < ActiveRecord::Base
validates_presence_of :content
scope :by_survey, lambda { |survey| where("survey_id = ?", survey) }
+ scope :anonymous, where(:anonymous => true)
+ scope :not_anonymous, where(:anonymous => false)
def my_questions
Question.by_survey(self.survey_id).map(&:id)
View
4 app/models/response.rb
@@ -18,12 +18,16 @@ class Response < ActiveRecord::Base
#SPEC 5.5.1.2 User ID's
belongs_to :answer
belongs_to :user
+ has_one :question, :through => :answer
# A user can only have one response per question per survey
# (something of the form validates_uniquness of
# http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000086
validates_uniqueness_of :question_id, :scope => [:user_id], :message => "You have already answered that question!"
+ scope :anonymous, lambda { joins(:question).where("anonymous = true") }
+ scope :not_anonymous, lambda { joins(:question).where("anonymous = false") }
+
private
def self.who_answered_me(answer_id_in)
Response.where(:answer_id => answer_id_in).map(&:user).map(&:name)
View
7 app/views/take_surveys/new.html.erb
@@ -13,12 +13,15 @@
<%= content_tag_for(:li, answer) do %>
<% unless current_user.responses.find_by_question_id_and_answer_id(question.id, answer.id).nil? %>
<span class="my-response">
- <%= radio_button_tag "response[#{question.id}]", "#{answer.id}", :checked => true %>
+ <%= radio_button_tag "response[#{question.id}][answer_id]", "#{answer.id}", :checked => true %>
<%= label_tag :answer, answer.content %>
</span>
<% else %>
- <%= radio_button_tag "response[#{question.id}]", "#{answer.id}", question.allow_free_response %>
+ <%= radio_button_tag "response[#{question.id}][answer_id]", "#{answer.id}", question.allow_free_response %>
<%= label_tag :answer, answer.content %>
+ <% if question.allow_free_response %>
+ <br /><%= text_area_tag "response[#{question.id}][content]", nil, :rows => 3, :cols => 40 %>
+ <% end %>
<% end %>
<% end %>
<% end %>
View
5 app/views/take_surveys/show.html.erb
@@ -20,6 +20,11 @@
<% else %>
<%= label_tag :answer, answer.content %>
<% end %>
+ <% if question.allow_free_response %>
+ <br /><br /><%= text_area_tag :content,
+ current_user.responses.find_by_question_id_and_answer_id(question.id, answer.id).content,
+ :rows => 3, :cols => 40, :disabled => true %>
+ <% end %>
<% end %>
<% end %>
</ol>
Please sign in to comment.
Something went wrong with that request. Please try again.