Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created January 9, 2009 05:46
Show Gist options
  • Save ahoward/45035 to your computer and use it in GitHub Desktop.
Save ahoward/45035 to your computer and use it in GitHub Desktop.
def temperature_variation_around_the_globe
allows :student, :studentdemo
setup_for_student
@disabled = disabled?
raise 'not student of this classroom!?' unless @student.classroom == @classroom
@school_data_questionnaire = @unit.teacher_class_profile_school_data_questionnaire
@completed = [@classroom, *@partners].map do |classroom|
classroom.teacher.has_answered_questionnaire?(@school_data_questionnaire, :context => classroom)
end
unless(@completed.first and (@completed.select{|complete| complete}.size >= 2))
render :template => 'unit/energy/temperature_variation_around_the_globe_denied' and return
end
partners =
@partners.select do |partner|
partner.teacher.has_answered_questionnaire?(@school_data_questionnaire, :context => partner)
end
@partners = partners[0,1]
@temperature_variation_over_the_year_questionnaire = @unit.temperature_variation_over_the_year_questionnaire
@questions = @temperature_variation_over_the_year_questionnaire.questions
@questions_and_answers =
@student.questions_and_answers_for(@temperature_variation_over_the_year_questionnaire, :context => @classroom, :blank => true)
@disabled ||= @questions_and_answers.submitted?
if request.post?
transaction do
params.keys.grep(%r/answer/).each do |key|
number = key.scan(%r/\d+/).first or raise("bad key #{ key }")
index = number.to_i - 1
pair = @questions_and_answers[index] or raise("bad key #{ key }")
answer = pair.answer or raise("bad key #{ key }")
value = params[key]
answer.answer = value.to_s.strip
if submitting?
answer.submit!
answer.publish!
end
answer.save!
end
end
if submitting?
message 'Thanks, your work has been submitted!', :class => 'success'
else
message 'Thanks, your work has been saved!', :class => 'success'
end
qq_redirect_to :action => 'index' and return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment