カスタムPDFが作成され、Paperclip経由でモデルに添付されている間に簡単なメッセージを表示しようとしています。完了したらプレビューを表示します。データベース内の処理状態を経由してSidekiqジョブを完了するための作業
私が見つけることができる最も簡単な解決策は、this questionのMike Perhamの応答です。 "データベースを使用して各写真の状態を保存し、Sidekiqに状態を更新させる。"
私はまだJavascript、JQuery、Rails &の良いSOの質問を書く方法を学んでいることに気づくはずです。それにもかかわらず、これまで私がフランケンシュタインに行ってきたことがあります。
私がここの正しい方向に取り組んでいるかどうか教えてください。
# generate_insert.rb
class GenerateInsert
include Sidekiq::Worker
def perform(customization_id)
customization = Customization.find(customization_id)
customization.update_attribute(:processing, true)
# code to perform, generate PDF via Prawn and attach via Paperclip
customization.update_attribute(:processing, false)
customization.save!
end
end
# customizations/show.html.erb
<div id='message'>First Message</div>
# messages.js
var i = 1;
var sampleMessages = [ "First Message", "Second Message", "Third Message" ];
setInterval(function() {
var newText = sampleMessages[i++ % sampleMessages.length];
$("#message").fadeOut(500, function() {
$(this).text(newText).fadeIn(500);
});
}, 1 * 3000);
});
# show.js.erb
$("#message").replaceWith("<%= j render 'customization' %>");
# poller.js
CustomizationPoller =
poll: ->
setTimeout @request, 5000
request: ->,
$.get($('???').data('url'))
jQuery ->
if $('#???').length > 0 // customization processing?
CustomizationPoller.poll()
ありがとうございました。 – rclark