I am trying to Upload videos in my app using Paperclip and jquery-fileupload-rails
I followed ulpoad file with paper clip and jquery to upload video, but was uploading video just as I select the video and don't wait for pressing submit button, So I followed 1: jQuery file upload: Is it possible to trigger upload with a submit button? to select a single video and upload it on submit button, not on selecting file.
But There is issue on whether I put submit button in the form or outside form.
When I put the submit button in the form than it sends two requests to pressing submit button, one with Video and second one without Video.
And If I put button outside form that it sends one request on pressing submit button but after successful create/update it remains on the same page.
All I wanted is that on pressing Submit, sending just one request and redirect to index page on successful create/update.
In _form.slim
= simple_form_for [:admin,add] do |f|
.wizard-content
.row
.col-sm-6
= f.input :video, multiple: false, wrapper: :horizontal_file_input
button#submit_button.btn.btn-primary
| Save
In adds.coffee
jQuery ->
$('#add_video').attr('name','add[video]')
$('#add_video').fileupload
$('#submit_button').off('click').on 'click', ->
data.submit()
In controller I have
def create
if add.save
redirect_to admin_adds_path
flash[:success]= "Add Created"
else
render :new
end
end
def update
if add.update(add_params)
redirect_to admin_adds_path
flash[:success]= "Add Updated"
else
render :edit
end
end
there is also a _add.slim
= image_tag(@add.uploaded_file(:small), class: 'thumb')
I also created create.js.erb and edit.js.erb as suggested tutorial I followed (though, I didn't understand its use )
- if @add.new_record?
| alert('Failed');
- else
| if ($('h1') !== undefined) { $('h1').append("
=j render partial: 'adds/add', locals: { add: @add }
| "); }
Whats wrong with this?