title: How to display flash error without refreshing page?
body: <p>I have a submit form that is shown in a lightbox. I validate the form pretty heavily but there are circumstances where a playlist is already submitted, in which case I can't tell before a form is submitted.</p>
  
  <p>Currently I have <code>:disable_with =&gt; 'Submitting...'</code></p>
  
  <p>It would be completely awesome if the error was sent back to the form, and the submit button would re-enable.</p>
  
  <p>Would this be possible without too much complication?</p>
  
  <p>I also have a second related question... Because my form is in a lightbox, it's code is actually ON the index page (my app is just one page pretty much). This means that there really is no 'new' action, but rather a <code>@playlist = Playlist.new(:title =&gt; ...)</code> in my index action (along with a <code>@playlists = Playlist.all</code>, etc). In my routes I did this: <code>resources :playlists, :only =&gt; [:create]</code></p>
  
  <p>Does this sound about right the way I did it?</p>
  
  <p>EDIT: HEre is some code, although it's basically about as simple as you can imagine it.</p>
  
  <p>The following kind of works... it creates the playlist if its valid, otherwise it does nothing. Both times create.js.erb is called.. i just dont now how to make this work to completion now. on success i need to close the window, on failure i need to load the errors into the form thats already on the screen. Im not sure where that goes though :/</p>
  
  <pre><code>  before_filter :load_genres, :only =&gt;[:index, :user]
    before_filter :new_playlist, :only =&gt; [:index, :new]
  
    def index
      @playlists = Playlist.order('created_at DESC').page(params[:page]).per(30)
    end
  
    def create
      @playlist = Playlist.new(params[:playlist])
      respond_to do |format|
        if @playlist.save
          format.html { redirect_to root_path, :notice =&gt; "Playlist submitted" }
          format.js   {}
        else
          format.html { render :action =&gt; :new, :layout =&gt; !request.xhr? }
          format.js {}
        end
      end
    end
  
    def new
  
    end
  
    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
  </code></pre>
  
  <p>Heres the first like of my form (located in index.html.erb):</p>
  
  <p><code>&lt;%= form_for @playlist, :remote =&gt; true do |f| %&gt;</code></p>
  
  <p>I currently have no html or code in <code>create.html.erb</code></p>