Rails file upload with ajax

i have been uploading file with rails with rest-client, but when i change that into ajax, gives some server error.

FORM code

<%= form_tag({:controller => 'person',:action => 'create'},:multipart => true) do
<%= file_field_tag 'upload', :class => 'upload_name' %>
<%= submit_tag "Upload",  :class => "photo_up btn btn-success" %>   

AJAX code


var filename = $(".upload_name").val();

         url: '/create', //your server side script
         data: { upload: filename}, //our data
         type: 'POST',
         success: function (response) {                        

return false;


file_param = params[:upload]
puts "name os #{file_param}"
show_url = "............."
resource = RestClient::Resource.new show_url, :user => "admin",:password => "admin"
response = resource.post  :file => file_param, :multipart => true

Here when i run this code, got the serve error RestClient::InternalServerError (500 Internal Server Error):, and i know that the server shows the null pointer, in the controller it gives the error in this line response = resource.post :file => file_param, :multipart => true. But its run when in the normal form without ajax.


Unfortunately there is no easy and universal way to send multipart forms via ajax

Look into jQuery ajaxForm plugin. This makes this thing easy.


Need Your Help

Where can I find a sample for Pcap for Diameter protocol (WireShark)?

pcap wireshark-dissector diameter-protocol

I was wondering if there are any sample wireshark pcaps for diameter protocol out there? If so please share.

SRS: Can these to be included?

architecture documentation software-engineering requirements srs

Think we are creating the "Glossary" of an SRS in tabular format. It has "Terms" and "Definition" as columns.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.