title: :remote => true confusion with form_for
body: <p>I'm just learning Rails and would appreciate any help. I've looked at probably 10 tutorials for <code>:remote =&gt; true</code> on <code>form_for</code> and they all seem to copy each other (equally confusing).</p>
  
  <p>This tutorial is one of them: <a href="http://tech.thereq.com/post/18910961502/rails-3-using-form-remote-true-with-jquery-ujs" rel="nofollow">http://tech.thereq.com/post/18910961502/rails-3-using-form-remote-true-with-jquery-ujs</a></p>
  
  <p>My web app is pretty much all on one page, and my 'submit form' is inside a pop-up lightbox. This means that the form_for code is actually within my index.html.erb. It also means a new @playlist instance variable is created for <code>index</code> (instead of having this be in <code>new</code>)</p>
  
  <p><strong>My end goal is this</strong>:</p>
  
  <p><code>if @playlist.save</code> returns <code>true</code>, I want to REDIRECT the user to the <code>root_path</code> WITH a :notice. There is no need to update the form with a success message or anything like that. I want a hard redirect on save success.</p>
  
  <p><code>if @playlist.save</code> returns <code>false</code>, I want to render the code inside create.js.erb, which will append the errors into the lightbox form without refreshing the page. <strong>note</strong> A lot of the tutorials seem to want to re-render the entire form as html, then replace the contents in place. I'd rather (if I can), just send the errors to the form and insert them, I think re-rendering and replacing the entire form seems more complicated than it has to be.</p>
  
  <p><strong>As of right now</strong>, my code is kind of muddled, especially:</p>
  
  <ul>
  <li>the <code>respond_to</code> block. This is the largest point of confusion about what actually goes here, I have tried lots of different code and nothing works</li>
  <li>I have no idea if create.js.erb is correct</li>
  <li>I have no create.html.erb - I assume this is right because I just want to redirect</li>
  </ul>
  
  <p><strong>First line of my form</strong>:</p>
  
  <pre><code>&lt;%= form_for @playlist, :remote =&gt; true do |f| %&gt;
  </code></pre>
  
  <p><strong>My entire PlaylistsController</strong></p>
  
  <pre><code>class PlaylistsController &lt; ApplicationController
  
    before_filter :load_genres, :only =&gt;[:index, :user]
    before_filter :new_playlist, :only =&gt; [:index, :new, :create]
  
    def index
      @playlists = Playlist.order('created_at DESC').page(params[:page]).per(30)
    end
  
    def new
    end
  
    def create
      respond_to do |format|
        if @playlist.save
          # ???
          format.html { redirect_to root_path, :notice =&gt; "Playlist submitted" }
        else
          # ???
          format.js { render :js =&gt; @playlist.errors, :status =&gt; :unprocessable_entity }
        end
      end
    end
  
    def user
      @playlists = Playlist.order('created_at DESC').where(:username =&gt; params[:username]).page(params[:page]).per(30)
    end
  
    def listen
      playlist = Playlist.find(params[:playlist_id])
      playlist.update_attribute(:listens, playlist.listens + 1)
      render :nothing =&gt; true
    end
  
    private
  
    def load_genres
      @genres = Genre.order(:name)
    end
  
    def new_playlist
      @playlist = Playlist.new(:title =&gt; params[:title], :url =&gt; params[:url], :description =&gt; params[:description])
    end
  
  end
  </code></pre>
  
  <p><strong>create.js.erb</strong></p>
  
  <pre><code>jQuery(function($) {
      alert('createjs called');
      $('#submit-form form').on('ajax:error', function(event, xhr, status, error){
  
          var responseObject = $.parseJSON(xhr.responseText), 
              errors = $('&lt;ul /&gt;');
  
          $.each(responseObject, function(index, value){
              errors.append('&lt;li&gt;' + value + '&lt;/li&gt;');
          })
  
          $(this).find('.submit-playlist-errors').html(errors);
      });
  });
  </code></pre>