Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endless survey loop #5

Closed
yoon opened this issue Sep 23, 2009 · 3 comments
Closed

endless survey loop #5

yoon opened this issue Sep 23, 2009 · 3 comments

Comments

@yoon
Copy link
Member

yoon commented Sep 23, 2009

welcome page, finishing page

@yoon
Copy link
Member Author

yoon commented Sep 23, 2009

on a per survey basis

@mgurley
Copy link
Member

mgurley commented Sep 23, 2009

In order to stop the endless loop I modified the following files.

controllers/surveying_controller.rb
views/surveying/edit.html.haml

In the Surveying controller I modified the update action to the following(this code has redirect to url paths specific to my application):

def update
  finished = false
  if params[:responses] or params[:response_groups]
    saved = @response_set.update_attributes(:response_attributes => (params[:responses] || {}).dup , :response_group_attributes => (params[:response_groups] || {}).dup) #copy (dup) to preserve params because we manipulate params in the response_set methods
    if (saved && params[:finish])
      @response_set.complete!
      saved = @response_set.save!
      finished = true
    end
  end
  respond_to do |format|
    format.html do
      if (finished && saved)
        flash[:notice] = "Completed survey"
        redirect_to user_path(current_user)
      else
        flash[:notice] = saved ? "" : "Unable to update survey" unless saved.nil? # Saved is nil if there are no questions on the page (ie if it only contains a label)
        redirect_to :action => "edit", :anchor => @anchor, :params => {:section => @section.id}
      end
    end
    # No redirect needed if we're talking to the page via json
    format.json do
        dependent_hash = dependents(@response_set)
        @dependents = dependent_hash[:show]
        render :json => {:show => dependent_hash[:show].map{|q| question_id_helper(q)}, :hide => dependent_hash[:hide].map{|q| question_id_helper(q)} }.to_json
    end
  end
end

I modified edit.html.haml to give the submit button a name of "finish" if there is not a next section like so:

 = @section.next ? section_next_helper(@section.next) : submit_tag("Click here to finish", :name => "finish")

@yoon
Copy link
Member Author

yoon commented Sep 28, 2009

fix for endless survey loop, allowing customizing surveyor default finish page. cleanup of extra controllers. thanks mgurley. closed by adb972c

ewto referenced this issue in ewto/surveyor Jun 14, 2011
another change to fix the caching
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants