ruby - Rails 4: How to upload files with AJAX -


i want upload files ajax. in past accomplished using magical jquery form plugin , worked great. i'm building rails app , trying things "the rails way" i'm using form helper , paperclip gem add file attachments.

the rails docs warn form helper not work ajax file uploads:

unlike other forms making asynchronous file upload form not simple providing form_for remote: true. ajax form serialization done javascript running inside browser , since javascript cannot read files hard drive file cannot uploaded. common workaround use invisible iframe serves target form submission.

it seems clear there's no off-the-shelf solution. i'm wondering what's smartest thing do. seems have several options:

  1. use form helper , iframe trick.
  2. use form helper + load jquery form plugin submit file (not sure if play nice rails's authenticity token, etc)
  3. use form helper + paperclip + [some other gem] extend it's functionality allow ajax form submission.

all 3 seem possible. know least #3, [some other gem] part. found 2 similar questions (this , this) mention branch of pic-upload called uploadify both 2 years old , deal rails 2 , 3 (and uploadify hasn't been updated in years). given how has changed, think whole new question:

what's best way upload files ajax in rails 4?

have remotipart gem: https://github.com/jangosteve/remotipart -- may of way there little work!


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -