title: render :edit causes form URL to change / fail after update
body: <p>I currently have a <b>working</b> form that breaks <i>after</i> I call <code>render :edit</code> in #update. After <code>render :edit</code> in #update  <strong>the URL for the #edit page changes</strong> from <code>questionnaires/1/edit</code> to <code>questionnaires/1</code> .</p>
  <p>Unlike most forms, my #edit and #show pages are different pages that represent different steps within this two-part form.  After <code>render :edit</code>, any new attempt at saving or submitting fails presumably because #edit (<i>PUT <code>questionnaires/1/edit</code></i>) now shares the same route with #show <i>(GET <code>questionnaires/1/edit</code>)</i></p>
  <p>The form saves properly with redirect_to but in this case I need to use render to retrieve error messages.</p>
  <h1>How do I get the persistance of <code>render</code> without breaking my form url?</h1>
  <hr />
  <p>Additional Details (if needed):</p>
  <p>The form allows users to save or submit changes.  After submission <code>check_if_finished</code> is run in Questionnaire.rb to add error messages to the Questionnaire form if any exist.   (Since the form needs to be saveable even when missing fields are present, I avoided using validations with save to generate errors)</p>
  <pre><code>class Questionnaire &lt; ActiveRecord::Base
    include HashKey
    
    belongs_to :nanny, foreign_key: :nanny_recruit_id
    accepts_nested_attributes_for :nanny
    has_one :driving_ability
  
  
  . . .
  
    def check_if_finished
      errors.add(:first_name, (custom_error_opening + 'requires answer')) if nanny.first_name.empty?
      errors.add(:last_name, &quot;requires answer&quot;) if nanny.last_name.empty?
      errors.add(:preferences, &quot;must select at least one preference&quot;) if self.preferences.empty?
    end
  
  . . .
  end
  </code></pre>
  <p>In my controller the first step of the form is in #edit.  After an #update to #edit, I redisplay the #edit page using <i><code>render :edit</code></i>.  The form saves properly with redirect_to, but I can't use <code>redirect_to</code> since that reloads the #edit page without persistance, meaning that my error messages won't show up unless I heavily refactor my errors into something like a Flash message.</p>
  <pre><code>class QuestionnairesController &lt; ApplicationController
    layout 'public'
    before_filter :find_questionnaire, only: [:edit, :update, :show, :destroy]
    # before_filter :set_commit_param
  
    # GET /questionnaires/1
    def show
      build_nanny_associations
    end
  
      # GET /questionnaires/new
      def new
        @questionnaire = Questionnaire.new
        build_nanny_associations
      end
  
      # GET /questionnaires/1/edit
      def edit
        build_nanny_associations
      end
  
      # POST /questionnaires
      def create
        @questionnaire = Questionnaire.new(params[:questionnaire])
        if @questionnaire.save
          redirect_to(@questionnaire, :notice =&gt; 'Questionnaire was successfully created.')
        else
          render :action =&gt; &quot;new&quot;
        end
      end
  
      # PUT /questionnaires/1
      def update
        update_questionnaire
        render :edit and return unless @questionnaire.valid?
        if params[:commit].match('Next &gt;&gt;')
          @questionnaire.check_if_finished
          render :edit and return unless @questionnaire.errors.empty?
          flash[:success] = ['Questionnaire Step 1 finished!']
          redirect_to questionnaire_path(@questionnaire)
        else
          (flash[:notice] = ['Application Saved!']) + (flash[:info] = questionnaire_url_explanation)
          redirect_to edit_questionnaire_path(@questionnaire)
        end
      end
  
    # DELETE /questionnaires/1
    def destroy
      @questionnaire.destroy
      redirect_to(questionnaires_url)
    end
  
    private
  
    def update_questionnaire
      @questionnaire.update_attributes(params[:questionnaire])
    end
  
    def build_nanny_associations
      @questionnaire.educations.build if @questionnaire.educations.empty?
      @questionnaire.build_driving_ability
      @questionnaire.driving_ability.driving_ability_cars.build
      if @questionnaire.nanny_times.empty?
        (0..6).to_a.each do |n|
          @questionnaire.nanny_times.build(day: n)
        end
      end
    end
  
    # def set_commit_param
    #   params[:commit] ||= &quot;&quot;
    # end
  
    def questionnaire_url_explanation
      [&quot;If you need more time to fill out your application, you can revisit this page by checking the link sent to your email, or by visiting: #{url_for(@questionnaire)} &quot;]
    end
  
    def find_questionnaire
      NannyRecruit.new # this is here to have rails autoload this class
      @questionnaire = Questionnaire.find_by_hash_key(params[:id])
    end
  end
  </code></pre>
  <p>For further detail, here's a part of the form:</p>
  <pre><code>&lt;%= simple_form_for(@questionnaire, :html =&gt; {:class =&gt; 'form-horizontal'}) do |f| %&gt;
    &lt;%= f.error_notification %&gt;
    &lt;%= f.simple_fields_for :nanny do |n| %&gt;
      &lt;%= n.input :first_name %&gt;
      &lt;%= n.input :last_name %&gt;
      ... 
    &lt;% end %&gt;
  
  &lt;div id=&quot;driving_ability&quot;&gt;
    &lt;%= f.simple_fields_for :driving_ability do |da|%&gt;
      &lt;%= render 'questionnaires/driving_ability_fields', :f =&gt; da %&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  
  &lt;% end %&gt;
  </code></pre>
  <p>My Rails version is 3.0.9.  Here is the stack trace of the error that only gets generated when I used render :edit:</p>
  <pre><code>ActiveRecord::StatementInvalid in QuestionnairesController#update
  
  Mysql2::Error: Unknown column 'questionnaire_driving_ability_cars.driving_ability_id' in 'where clause': SELECT `questionnaire_driving_ability_cars`.* FROM `questionnaire_driving_ability_cars` WHERE `questionnaire_driving_ability_cars`.`id` IN (8) AND (`questionnaire_driving_ability_cars`.driving_ability_id = 8)
  
  
  Application Trace | Framework Trace | Full Trace
  
  mysql2 (0.2.18) lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `query'
  mysql2 (0.2.18) lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `block in execute'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract_adapter.rb:202:in `block in log'
  activesupport (3.0.20) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract_adapter.rb:200:in `log'
  newrelic_rpm (3.4.1) lib/new_relic/agent/instrumentation/active_record.rb:32:in `block in log_with_newrelic_instrumentation'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
  newrelic_rpm (3.4.1) lib/new_relic/agent/instrumentation/active_record.rb:29:in `log_with_newrelic_instrumentation'
  mysql2 (0.2.18) lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `execute'
  mysql2 (0.2.18) lib/active_record/connection_adapters/mysql2_adapter.rb:586:in `select'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract/query_cache.rb:54:in `block in select_all'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `cache_sql'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract/query_cache.rb:54:in `select_all'
  activerecord (3.0.20) lib/active_record/base.rb:473:in `find_by_sql'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:493:in `block in find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:488:in `find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
  activerecord (3.0.20) lib/active_record/relation.rb:64:in `to_a'
  activerecord (3.0.20) lib/active_record/relation/finder_methods.rb:143:in `all'
  activerecord (3.0.20) lib/active_record/base.rb:444:in `all'
  activerecord (3.0.20) lib/active_record/associations/association_collection.rb:444:in `block in method_missing'
  activerecord (3.0.20) lib/active_record/base.rb:1131:in `with_scope'
  activerecord (3.0.20) lib/active_record/associations/association_proxy.rb:212:in `with_scope'
  activerecord (3.0.20) lib/active_record/associations/association_collection.rb:440:in `method_missing'
  activerecord (3.0.20) lib/active_record/nested_attributes.rb:364:in `assign_nested_attributes_for_collection_association'
  activerecord (3.0.20) lib/active_record/nested_attributes.rb:254:in `driving_ability_cars_attributes='
  activerecord (3.0.20) lib/active_record/base.rb:1569:in `block in attributes='
  activerecord (3.0.20) lib/active_record/base.rb:1565:in `each'
  activerecord (3.0.20) lib/active_record/base.rb:1565:in `attributes='
  activerecord (3.0.20) lib/active_record/associations/association_proxy.rb:227:in `method_missing'
  activerecord (3.0.20) lib/active_record/nested_attributes.rb:388:in `assign_to_or_mark_for_destruction'
  activerecord (3.0.20) lib/active_record/nested_attributes.rb:296:in `assign_nested_attributes_for_one_to_one_association'
  activerecord (3.0.20) lib/active_record/nested_attributes.rb:254:in `driving_ability_attributes='
  activerecord (3.0.20) lib/active_record/base.rb:1569:in `block in attributes='
  activerecord (3.0.20) lib/active_record/base.rb:1565:in `each'
  activerecord (3.0.20) lib/active_record/base.rb:1565:in `attributes='
  activerecord (3.0.20) lib/active_record/persistence.rb:133:in `block in update_attributes'
  activerecord (3.0.20) lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
  activerecord (3.0.20) lib/active_record/transactions.rb:207:in `transaction'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:493:in `block in transaction_with_trace_ActiveRecord_self_name_transaction'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:488:in `transaction_with_trace_ActiveRecord_self_name_transaction'
  activerecord (3.0.20) lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
  activerecord (3.0.20) lib/active_record/persistence.rb:132:in `update_attributes'
  app/controllers/nanny_application_questionnaires_controller.rb:61:in `update_nanny_application_questionnaire'
  app/controllers/nanny_application_questionnaires_controller.rb:35:in `update'
  actionpack (3.0.20) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.0.20) lib/abstract_controller/base.rb:150:in `process_action'
  actionpack (3.0.20) lib/action_controller/metal/rendering.rb:11:in `process_action'
  actionpack (3.0.20) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.0.20) lib/active_support/callbacks.rb:442:in `block in _run__3469136786962682921__process_action__1830587528925346581__callbacks'
  activesupport (3.0.20) lib/active_support/callbacks.rb:221:in `block in _conditional_callback_around_48239'
  activesupport (3.0.20) lib/active_support/callbacks.rb:331:in `around'
  activesupport (3.0.20) lib/active_support/callbacks.rb:315:in `_callback_around_11'
  activesupport (3.0.20) lib/active_support/callbacks.rb:220:in `_conditional_callback_around_48239'
  activesupport (3.0.20) lib/active_support/callbacks.rb:431:in `_run__3469136786962682921__process_action__1830587528925346581__callbacks'
  activesupport (3.0.20) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
  activesupport (3.0.20) lib/active_support/callbacks.rb:94:in `run_callbacks'
  actionpack (3.0.20) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.0.20) lib/action_controller/metal/rescue.rb:17:in `process_action'
  actionpack (3.0.20) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.0.20) lib/active_support/notifications.rb:52:in `block in instrument'
  activesupport (3.0.20) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (3.0.20) lib/active_support/notifications.rb:52:in `instrument'
  actionpack (3.0.20) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  newrelic_rpm (3.4.1) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:34:in `block in process_action'
  newrelic_rpm (3.4.1) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:262:in `block in perform_action_with_newrelic_trace'
  newrelic_rpm (3.4.1) lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
  newrelic_rpm (3.4.1) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:257:in `perform_action_with_newrelic_trace'
  newrelic_rpm (3.4.1) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:33:in `process_action'
  actionpack (3.0.20) lib/abstract_controller/base.rb:119:in `process'
  actionpack (3.0.20) lib/abstract_controller/rendering.rb:41:in `process'
  actionpack (3.0.20) lib/action_controller/metal.rb:138:in `dispatch'
  actionpack (3.0.20) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.0.20) lib/action_controller/metal.rb:178:in `block in action'
  actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:68:in `call'
  actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:68:in `dispatch'
  actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:33:in `call'
  rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
  rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
  rack-mount (0.6.14) lib/rack/mount/code_generation.rb:103:in `optimized_each'
  rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
  rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
  actionpack (3.0.20) lib/action_dispatch/routing/route_set.rb:499:in `call'
  newrelic_rpm (3.4.1) lib/new_relic/rack/browser_monitoring.rb:12:in `call'
  newrelic_rpm (3.4.1) lib/new_relic/rack/developer_mode.rb:24:in `call'
  pdfkit (0.5.2) lib/pdfkit/middleware.rb:16:in `call'
  warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
  warden (1.1.1) lib/warden/manager.rb:34:in `catch'
  warden (1.1.1) lib/warden/manager.rb:34:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/head.rb:14:in `call'
  rack (1.2.8) lib/rack/methodoverride.rb:24:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/flash.rb:182:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/cookies.rb:302:in `call'
  activerecord (3.0.20) lib/active_record/query_cache.rb:32:in `block in call'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
  activerecord (3.0.20) lib/active_record/query_cache.rb:12:in `cache'
  activerecord (3.0.20) lib/active_record/query_cache.rb:31:in `call'
  activerecord (3.0.20) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
  activesupport (3.0.20) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
  actionpack (3.0.20) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
  rack (1.2.8) lib/rack/sendfile.rb:106:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
  railties (3.0.20) lib/rails/rack/logger.rb:13:in `call'
  rack (1.2.8) lib/rack/runtime.rb:17:in `call'
  rack (1.2.8) lib/rack/lock.rb:13:in `block in call'
  &lt;internal:prelude&gt;:10:in `synchronize'
  rack (1.2.8) lib/rack/lock.rb:13:in `call'
  actionpack (3.0.20) lib/action_dispatch/middleware/static.rb:30:in `call'
  railties (3.0.20) lib/rails/application.rb:168:in `call'
  railties (3.0.20) lib/rails/application.rb:77:in `method_missing'
  railties (3.0.20) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.2.8) lib/rack/content_length.rb:13:in `call'
  rack (1.2.8) lib/rack/handler/webrick.rb:52:in `service'
  /Users/kelsey/.rbenv/versions/1.9.3-p547/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /Users/kelsey/.rbenv/versions/1.9.3-p547/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /Users/kelsey/.rbenv/versions/1.9.3-p547/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
  </code></pre>