Recent Posts

Recent Comments

    Archives

    Categories

    Meta

    Revolution Slider Error: The param Slider Width should not be empty.

    How to upload files using ajax in Rails 5

    Previos Post

    Do you have a file field in your form and are you struggling to figure out why everytime you attempt to upload an image or a file using ajax you get raw json in your browser, this is why –

    Javascript cannot handle the file uploading, so you have to do some tweaking! First off, you need to install a gem like remotipart –

    gem 'remotipart'
    1. Put that in your gemfile
    bundle install

    2. Run bundle install in your command line

    <%= form_for @post, remote: true, format: 'js', html: { multipart: true }  do |f| %>

    3. Add remote: true, format: ‘js’, html: {multipart: true} to your form for helper code and remotipart will now create an iframe            to upload your file.

    I will update this to give a full tutorial using aws and carrierwave to uplod said file later. I just wanted to get this out there because this took me a while to figure it out. Hopefully this will allow you to figure it out in just a couple of minutes!

     

    Here is the remotipart git hub –

    https://github.com/JangoSteve/remotipart

    Previos Post Share:

    More Posts

    Leave a Reply