Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Dreven's Profile

GitHub User: Dreven

Comments by

Avatar

If it helps anyone, this is what I ended up with in my RJS file - assuming I had hidden 'folder_notice_success' and 'folder_notice_fail' divs above the form and I had a simple form that could only possibly return one error. I need to clean this up (and I have no idea what I'm doing), but it seems to work great. I'm also calling a Javascript function in the view that uses and AJAX call to refresh a list of folders (since this is all from a form_remote that creates a new folder). But, I'm only calling that function if the @folder.save was successful:

CONTROLLER:
    respond_to do |format|
       if @folder.save
          flash[:notice] = "New folder successfully created!"
          format.html { redirect_to 'new' }
          format.js
       else
          flash[:error] = "doesn't matter right now as long is something is here."
          format.html { redirect_to 'new' }
          format.js
        end
    end

RJS FILE:
if !flash[:notice].blank?
    page[:folder_name].value = ''
    page.replace_html :folder_notice_success, flash[:notice]
    page[:folder_notice_success].show
    page.delay(3) do
      page[:folder_notice_success].hide
    end
    page << "folder_lookup()"
elsif !flash[:error].blank?
    page.replace_html :folder_notice_fail, 'ERROR: ' + @folder.errors.to_xml
    page[:folder_notice_fail].show
    page.delay(4) do
      page[:folder_notice_fail].hide
    end
end
flash.discard