Created
August 24, 2011 11:09
-
-
Save jaylevitt/1167806 to your computer and use it in GitHub Desktop.
Icky way to do request-response async handling in RAILS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SurveyController | |
# GET | |
def show | |
ss = SurveyState.new(params[:survey]) | |
ss.next_question_group do |question| | |
render :partial => 'question', :object => question | |
end | |
session[:survey_state] = ss.id | |
end | |
# POST | |
def update | |
ss = SurveyState.find(session[:survey_state]) | |
ss.record_responses(params) | |
if ss.more_questions_to_show? | |
redirect :show | |
elsif ss.done_with_this_survey? | |
redirect :show_survey_results | |
else | |
# implicit return to mainloop; we didn't get the AJAX response for every question and | |
# will wait for the rest to show up | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment