Is there how to upload files using ajax?

AJAX uploads are not supported out of the box, you can check this page for help: http://sean.treadway.info/demo/upload/ and http://sean.treadway.info/svn/plugins/responds_to_parent/README

Best regards

Peter De Berdt

Install the plugin by entering "script/plugin install http://sean.treadway.info/svn/plugins/responds_to_parent/" in the terminal.

The readme of respond_to_parent will show you how to use it:
http://sean.treadway.info/svn/plugins/responds_to_parent/README

If you're really uncomfortable with all of this, just use the normal form submit (don't use ajax). It will be hard to maintain something if you don't understand how it works.

Best regards

Peter De Berdt

I’ve read the readme and even created a project thats exactly the same.

This line results not one but two RJS template errors.

page << “alert($(‘stuff’).innerHTML)”

Tsk tsk tsk, the readme is a quick and dirty draft, the form wasn’t set to multipart, but as soon as you replace it with rails style erb tags, everything runs fine.

Example:

class TestController < ApplicationController

def main

end

def form_action

Do stuff with params[:uploaded_file]

if params[:uploaded_file]

responds_to_parent do

render :update do |page|

page << “alert(’#{params[:uploaded_file].original_filename}’)”

end

end

else

render :nothing => true

end

end

end

main.rhtml

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>Test</title>
Here is some stuff

<%= start_form_tag({:action => ‘form_action’}, :multipart => true, :target => “frame”) %>

<%= file_field_tag(“uploaded_file”)%>

<%= submit_tag(‘Save’)%>

<%= end_form_tag %>

Best regards

Peter De Berdt