Question

I am a kind of new on ROR, I want to upload an image using simple input tag and don't want to use form for that. The basic functionality of Paperclip is known to me. If I am not wrong then the format of object that is being passed to save image is :

"image_object"=>
  [#< ActionDispatch::Http::UploadedFile:0xb5ad25f4
    @content_type="image/gif",
    @headers=
     "Content-Disposition: form-data; name=\"pic[]\"; filename=\"test.gif\"\r\nContent-Type: image/gif\r\n",
    @original_filename="test.gif",
    @tempfile=#<File:/tmp/RackMultipart20131112-17750-1lprijc>>]

I want to upload image using the following steps: 1. Using Jquery, I want to fetch the appropriate details(file parameter) of selected image in input tag and send those using Jquery/ajax. 2. By passing that parameters to rails controller I want to use those details to generate an object(as sample shown above) that can be used to save Image in my application.

My questions are: 1. which Jquery method should I use and what are the parameters that are necessary to generate the image object? 2. On controller side, how to generate Image Object using those details?

Thanks in advance.

Was it helpful?

Solution

I'm not sure if I understood your question right. But based on the details you provided there are many options you can go for.

The simplest one is as follows:

Just add :remote => true to the rails form and submit the form and on the controller side you can create the object.

But if you want to be able to upload an image through a REST API then this link should help.

You can visit the SO question as well here which describes exactly what u want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top