How to check from view if processing?
dt1973 opened this issue · 1 comments
dt1973 commented
How to check from the view if an attachment is processing?
Can't get this to work:
photo.rb
class Photo < ActiveRecord::Base
has_attached_file :attachment,
styles: {
medium: "800x600#",
thumbnail: "70x70#"
}
validates_attachment :attachment, presence: true, content_type: {
content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]
}
process_in_background :attachment
before_post_process :set_attachment_is_processing
after_post_process :set_attachment_is_processing
private
def set_attachment_is_processing
self.attachment_is_processing = true if attachment.processing?
end
end
_post.html.erb
<% if photo.attachment_is_processing %>
<p>Please wait while we process your upload...</p>
<% else %>
<%= image_tag photo.attachment(:medium) %>
<% end %>
dt1973 commented
Apparently I just had to add the :attachment_processing
column and the rest is automatic. Shoutout to @zonecheung and @Xtinct.
photo.rb
class Photo < ActiveRecord::Base
has_attached_file :attachment,
styles: {
medium: "800x600#",
thumbnail: "70x70#"
}
validates_attachment :attachment, presence: true, content_type: {
content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]
}
process_in_background :attachment
end
_post.html.erb
<% if photo.attachment_processing %>
<p>Please wait while we process your upload...</p>
<% else %>
<%= image_tag photo.attachment(:medium) %>
<% end %>