未初始化的恒定Blitline宝石

时间:2013-12-05 17:05:36

标签: ruby-on-rails ruby ruby-on-rails-4 blitline

使用Blitline处理图像时遇到问题。我已经将gem添加到我的gemfile重启终端等...但是在rails控制台中,当我尝试测试它时出现此错误:

Loading development environment (Rails 4.0.1)
2.0.0p353 :001 > blitline_service = Blitline.new
NameError: uninitialized constant Blitline

当我尝试在我的应用程序中通过模型使用blitline时,我得到了同样的错误......

NameError in DrawingsController#create
uninitialized constant Drawing::Blitline

完整的型号代码

class Drawing < ActiveRecord::Base

    scope :published, -> { where(published: true) }

  attr_accessible :image, :title, :user_id, :week_id, :key, :published, :safe_for_kids

    #=mount_uploader :image, DrawingUploader

  belongs_to :week
  belongs_to :user

    def image_name
        File.basename(image.path || image.filename) if image
    end


    before_save :run_blitline_job

    private

    def run_blitline_job
      filename = File.basename(image, '.*')
      # self.title ||= sanitize_filename(filename).titleize # set default name based on filename

      filename_with_ext = File.basename(image)
      key = "uploads/thumbnails/#{SecureRandom.hex}/#{filename_with_ext}"

      bucket = ENV["S3_BUCKET"]

      images = blitline_job(image, bucket, key)
      self.image = images['results'][0]['images'][0]['s3_url'] # extracts s3_url from blitline's ruby hashes
    end

    def blitline_job(original_image, bucket, key)
      blitline_service = Blitline.new
      blitline_service.add_job_via_hash({ # New add job method in Blitline gem 2.0.1. Messy.
        "application_id" => ENV['BLITLINE_APPLICATION_ID'],
        "src" => original_image,
        "functions" => [{
            "name"   => "watermark", # watermark the image
            "params" => { "text" => "oh hai" },
            "functions" => [{
                "name"   => "resize_to_fill", # resize after watermark
                "params" => { "width" => 200, "height" => 200 },
                "save"   => {
                    "image_identifier" => "MY_CLIENT_ID", # Not sure what this is for
                    "s3_destination"   => { "key" => key, "bucket" => bucket } # push to your S3 bucket
                }
            }]
        }]
      })
      return blitline_service.post_jobs
    end

end

任何帮助表示赞赏...

0 个答案:

没有答案