File upload via Ajax
Quite an interesting method of downloading a file, although I think many people know it.
First, create a form and a hidden iframe into which the form itself will be sent (this is indicated by the target attribute). When the Submit button is clicked, the form will be sent to a hidden iframe, and the upload_action controller method will be called. Now you need to get the data in the context of the entire page (the parent window for the frame). A very interesting solution is used for this. We describe the controller for receiving and processing data from this form: The iframe call is implemented by the respond_to_parent plugin . To generate such a form with an iframe, you can use the remote_upload plugin. The decision in my opinion is very nice.
First, create a form and a hidden iframe into which the form itself will be sent (this is indicated by the target attribute). When the Submit button is clicked, the form will be sent to a hidden iframe, and the upload_action controller method will be called. Now you need to get the data in the context of the entire page (the parent window for the frame). A very interesting solution is used for this. We describe the controller for receiving and processing data from this form: The iframe call is implemented by the respond_to_parent plugin . To generate such a form with an iframe, you can use the remote_upload plugin. The decision in my opinion is very nice.
<br>
<br>
/><br>
/><br>
<br>
<br>
<br>
class UploadController < ActionController::Base<br>
def upload_action<br>
responds_to_parent do<br>
File.open("public/files/upl_file",'wb') do |file| <br>
file.write params[:upl_data].read <br>
end <br>
render :update do |page|<br>
page.replace_html 'upload_frm', :partial => 'upload'<br>
end<br>
end<br>
end <br>
end<br>