title: Rails respond_to redirect not working
body: <p>The respond_to block in a create controller in my Rails app is not redirecting on a successful save... I'm sure this is a simple solution, but I am inexperienced with Rails and this is the first time that I am encountering this problem.</p>
  
  <p>The form is set so that :remote => true, and the controller is as follows...</p>
  
  <pre><code>def create
      @store = current_user.stores.new(store_params)
  
      respond_to do |format|
          if @store.save
              format.html { redirect_to root_path }
          else
              format.html { flash[:alert] = "Save failed! #{@store.errors.full_messages.join(";")}" 
              render "new" }
              format.js {}
          end
      end
  end
  </code></pre>
  
  <p>And while I'm on the subject, the code from the <em>else</em> portion of the conditional doesn't run either, except for <code>format.js {}</code>, which does run the code in my create.js.erb file (an alert, for the time being).</p>
  
  <p>I'm working with Rails 4.2.5.  Can someone help me to understand why the redirect and the alert are not working?  Thank you!</p>
  
  <p><strong>EDITING TO SHOW SOLUTION</strong>
  Based on Rich's answer, here's the solution that I came up with:</p>
  
  <p>Controller:</p>
  
  <pre><code>def create
      @store = current_user.stores.new(store_params)
  
      flash.now[:alert] = "Save failed! #{@store.errors.full_messages.join(";")}" unless @store.save
  
      respond_to do |format|
          format.js
      end
  
      if @store.save
          flash[:notice] = "New store created"
      end
  end
  </code></pre>
  
  <p>create.js.erb</p>
  
  <pre><code>&lt;% if flash.now[:alert] %&gt;
      $("#alert_holder").empty();
      $("#alert_holder").append("&lt;%= j flash.now[:alert] %&gt;");
  &lt;% else %&gt;
      window.location.href = "&lt;%= root_url %&gt;";
  &lt;% end %&gt;
  </code></pre>
  
  <p>Note that I needed to add quotes around the redirect url.</p>
  
  <p>On form success, the page redirects to root.  On failure, the error message flashes but the form is not refreshed - any answers the user has entered remain.</p>