Skip to content

Instantly share code, notes, and snippets.

@jaylevitt
Created August 24, 2011 11:09
Show Gist options
  • Save jaylevitt/1167806 to your computer and use it in GitHub Desktop.
Save jaylevitt/1167806 to your computer and use it in GitHub Desktop.
Icky way to do request-response async handling in RAILS
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