未初始化的常量PhotoUploader :: Cloudinary

时间:2019-06-01 09:50:01

标签: ruby-on-rails carrierwave

您好,我在过去的几个小时里一直在尝试使用载波将种子图像添加到种子文件中。我添加了我添加到模型中的宝石,也添加了控制器中的params,但是我仍然遇到此错误:NameError in ServicesController#index uninitialized constant PhotoUploader::Cloudinary

我一直在网上寻找为什么这可能无济于事。

我重新启动了服务器,弹簧停止了,关闭了终端并重新打开了,我还在我的service.rb文件的顶部添加了“ require carrierwave”,但没有任何效果。

谢谢。

service.rb

class Service < ApplicationRecord
  mount_uploader :photo, PhotoUploader
end

app / uploaders / photo_uploader.rb

class PhotoUploader < CarrierWave::Uploader::Base
  include Cloudinary::CarrierWave
end

服务控制器

class ServicesController < ApplicationController
before_action :find_service, only: [:show]

  def index
    if params[:category].present?
      @services = Service.where(category: params[:category])
    else
      @services = Service.all
    end
  end

  def show
  end

  private

  def service_params
    params.require(:service).permit(:name, :description, :category, :picture_url, :video, :photo, :photo_cache)
  end

  def find_service
    @service = Service.find(params[:id])
  end
end

gemfile:

gem 'carrierwave', '~> 1.2'

种子文件

Service.destroy_all
puts 'Creating services...'


Service.create!({
  name: "Carpet Cleaning Stain 1",
  description: "v stubborn",
  category: "stain removal",
  remote_photo_url: "https://res.cloudinary.com/dnsof9xnr/image/upload/v1558043148/58625931_1259911844176433_4676539998827184128_n_1.jpg"
})

我根据本教程添加了远程url行:https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Upload-remote-image-urls-to-your-seedfile

0 个答案:

没有答案