Virge Assault
Virge Assault

Reputation: 1396

uninitialized constant Car::PictureUploader

I'm trying to add a Picture Uploader in app/uploaders but am getting this error when loading my app:

uninitialized constant Car::PictureUploader on line 3 of car.rb

app/models/car.rb

class Car < ActiveRecord::Base
  belongs_to :user
  mount_uploader :picture, PictureUploader
  validates :user_id, presence: true
  validates :year, presence:true, length: { maximum: 4 }
  validates :brand, presence:true

app/uploaders/picture_uploader.rb

class PictureUploader < CarrierWave::Uploader::Base
  storage :file

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Add a white list of extensions which are allowed to be uploaded.
  def extension_white_list
    %w(jpg jpeg gif png)
  end
end

I've gotten this error before when the file equivalent to picture_uploader.rb wasn't in the correct folder, but I think everything is in order here. When I comment out line 3 in user.rb the page loads. Any idea on how I can get my page to run?

Upvotes: 1

Views: 2969

Answers (3)

Anand Raja
Anand Raja

Reputation: 3106

Just restart your server. It'll fix the issue. Everything is ok in your code.

Upvotes: 0

Pjotr Gainullin
Pjotr Gainullin

Reputation: 1057

Had the same error and had to manually kill the server process:

ps aux | grep server
kill [server process id]

For some reason shutting down the server with Ctrl+C earlier didn't seem to have worked.

Upvotes: 2

Katherine
Katherine

Reputation: 171

I think you want:

::PictureUploader

Which specifies that it's just the class PictureUploader not a class PictureUploader within the namespace Car.

Upvotes: 1

Related Questions