SystemStackError in Forem::TopicsController#create
stack level too deep
actionpack (4.1.2) lib/action_dispatch/middleware/reloader.rb:79
class Photo < ActiveRecord::Base
belongs_to :post, class_name: "Forem::Post"
ATTACHMENT_STYLES = lambda do |attachment|
if animated_gif?(attachment)
{medium: {format: "flv"}, thumbnail: {format: "png"}}
else
{medium: "x300>", thumbnail: "50x50#"}
end
end
ATTACHMENT_PROCESSORS = lambda { |instance| animated_gif?(instance.attachment) ? [:ffmpeg] : [:thumbnail] }
has_attached_file :attachment,
styles: ATTACHMENT_STYLES,
processors: ATTACHMENT_PROCESSORS,
url: "/:class/:attachment/:id/:style_:filename",
path: ":rails_root/public/system/:attachment/:id/:style/:filename"
validates_attachment :attachment, presence: true, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] }
def self.animated_gif?(attachment)
attachment_path = attachment.instance.new_record? ? attachment.queued_for_write[:original].path : attachment.path
rmagick = Magick::ImageList.new(attachment_path)
if attachment.content_type =~ /gif/ && rmagick.scene > 0
return true
# http://stackoverflow.com/questions/19338570/set-a-boolean-value-to-false
update_attribute(:attachment_is_animated, true)
end
end
end
module ApplicationHelper
def animated_gif?(photo)
true if photo.attachment_is_animated?
end
end
<% for photo in post.photos %>
<% if animated_gif?(photo) %>
<%= video_tag photo.attachment.url(:medium) %>
<% else %>
<%= image_tag photo.attachment.url(:medium) %>
<% end %>
<% end %>
rails generate migration AddAttachmentIsAnimatedToPhotos
class AddAttachmentIsAnimatedToPhotos < ActiveRecord::Migration
def self.up
add_column :photos, :attachment_is_animated, :boolean
end
def self.down
remove_column :photos, :attachment_is_animated, :boolean
end
end
Log in with [email protected]
/ admin1234
in order to upload.
Try this instead:
https://github.com/thoughtbot/paperclip#dynamic-processors