I found this gem to use the bootstrap progress bar and the delayed job gem together. In his example he uses .haml file, but I'm using erb and coffeescript in my project, so I tried to reproduce what he does.
This is my controller
def export
@job = Delayed::Job.enqueue StandingsJob.new
end
this is routes.rb
get 'export', to: 'scraper#export'
and this is my home.erb.html
<%= link_to 'export', export_path, {id:'mario', remote: true} %>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">
0%
</div>
</div>
and this is my coffeescript file
$(document).on "turbolinks:load", ->
$('#mario').on 'click', ->
alert('hocliccatoooo')
interval = setInterval( ->
$.ajax(
url: '/progress-job/' **** What should I add here?????****,
success: (job) ->
console.log('loool')
stage
progress
if job.last_error != null
$('.progress-status').addClass('text-danger').text(job.progress_stage);
$('.progress-bar').addClass('progress-bar-danger');
$('.progress').removeClass('active');
clearInterval(interval);
if job.progress_stage != null
stage = job.progress_stage
progress = job.progress_current / job.progress_max * 100
else
progress = 0
stage = 'Uploading file?'
if progress != 0
$('.progress-bar').css('width', progress + '%').text(progress + '%')
$('.progress-status').text(stage);
error: ->
alert('errore')
$('.progress').removeClass('active');
$('.progress-bar').css('width', '100%').text('100%');
$('.progress-status').text('Finito!!!');
clearInterval(interval);
)
, 100)
The code runs correctly when I click on the link, the only problem is, how can I tell to my coffeescript the id of the job that I created in my controller action? Thank you all
[EDIT]
This is my job
class StandingsJob < ProgressJob::Base
def perform
update_stage 'Faccio cose'
update_progress_max 10
for i in [0..10]
sleep(2)
update_progress
end
end
end
I did some digging and seems that the perfom method of my job is never fired(i put a puts 'lol' in my perform method and I never see it in the console)