Uninitialized Constant on Existing App

707 views
Skip to first unread message

Bryan

unread,
Jul 11, 2011, 10:15:40 PM7/11/11
to carrierwave
After following the railscasts at (http://railscasts.com/episodes/253-
carrierwave-file-uploads), I receive the following error. This was
performed on my existing rails 3 app. I tried it on a brand new rails
3 app created just for this purpose and everything ran fine. Any
ideas? Thanks in advance for the help.



[bryanrogers@RHEL6Workstation da-bv-rails]$ rails s
=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
app/models/game.rb:18:in `<class:Game>': uninitialized constant
Game::ImageUploader (NameError)
from app/models/game.rb:3:in `<top (required)>'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:46:in `block (2 levels) in <top
(required)>'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:45:in `each'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:45:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:47:in `class_eval'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:47:in `configure'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application/bootstrap.rb:11:in `block in <module:Bootstrap>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:25:in `instance_exec'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:25:in `run'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:50:in `block in run_initializers'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:49:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:49:in `run_initializers'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:134:in `initialize!'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:77:in `method_missing'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environment.rb:5:in `<top (required)>'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config.ru:
3:in `block in <main>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/
builder.rb:46:in `instance_eval'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/
builder.rb:46:in `initialize'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config.ru:
1:in `new'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config.ru:
1:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/
builder.rb:35:in `eval'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/
builder.rb:35:in `parse_file'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/
server.rb:162:in `app'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/
server.rb:253:in `wrapped_app'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/
server.rb:204:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/commands/server.rb:65:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/commands.rb:30:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/commands.rb:27:in `tap'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Alexandru-Emil Lupu

unread,
Jul 12, 2011, 2:32:45 AM7/12/11
to carri...@googlegroups.com

Hello!
Can we see how did you included your uploader? And what is inside game.rb model at line 3 & 18?
Can we see how your uploader declaration looks like?
On a first view ..  i would suspect that you have the uploader file in app/uploaders dir but you're using it wrong.
Alecs

On Jul 12, 2011 5:19 AM, "Bryan" <bryan....@digitalaugment.com> wrote:

Bryan

unread,
Jul 12, 2011, 2:45:18 AM7/12/11
to carrierwave
Thanks for the reply. The breakdown of the 2 files are as follows as
well as the error as genereated with this exact code. Thanks again
for your help.

---./app/uploaders/image_uploader.rb---

# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::ImageScience

# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog

# 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

# Provide a default URL as a default if there hasn't been a file
uploaded:
# def default_url
# "/images/fallback/" + [version_name,
"default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb
for details.
# def filename
# "something.jpg" if original_filename
# end

end

---./app/models/game.rb---

class Game < ActiveRecord::Base
attr_accessible :image
has_many :game_announcements
has_many :game_profiles, :dependent => :destroy
has_many :discussion_spaces
has_many :page_spaces
has_many :supported_games
has_many :communities, :through => :supported_games
mount_uploader :image, ImageUploader

validates_presence_of :name


after_create :create_game_discussion_space, :create_character_discussion_space

scope :active, :conditions => {:is_active => true}

def create_game_discussion_space
discussion_space = DiscussionSpace.create( :name => self.name+"
Announcements",
:system => true,
:game => self,
:announcement_space =>
true)
self.announcement_space_id = discussion_space.id
self.save
end

def create_character_discussion_space
discussion_space = DiscussionSpace.create( :name => self.name+"
Characters",
:system => true,
:game => self)
self.character_discussion_space_id = discussion_space.id
self.save
end

def announcement_space
DiscussionSpace.find_by_id(self.announcement_space_id)
end

def character_discussion_space
DiscussionSpace.find_by_id(self.character_discussion_space_id)
end

# def self.active
# Game.where("is_active = ?", true)
# end

# Lets the subclasses use the parents routes.
def self.inherited(child)
child.instance_eval do
def model_name
Game.model_name
end
end
super
end

# Used to offer a dynamically generated list of subclass to choose
from.
def self.select_options
descendants.map{ |c| c.to_s }.sort
end

def type_helper
self.type
end
def type_helper=(type)
self.type = type
end

def check_user_show_permissions(user)
user.can_show("Game")
end

def check_user_create_permissions(user)
user.can_create("Game")
end

def check_user_update_permissions(user)
user.can_update("Game")
end

def check_user_delete_permissions(user)
user.can_delete("Game")
end
end

---Error---

=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
app/models/game.rb:9:in `<class:Game>': uninitialized constant
Game::ImageUploader (NameError)
from app/models/game.rb:1:in `<top (required)>'

Alexandru-Emil Lupu

unread,
Jul 12, 2011, 3:04:50 AM7/12/11
to carri...@googlegroups.com
Hello!

Hmmmz it looks like the same thing i have (regarding the uploader part)

in my : app/models/picture.rb

class Picture < ActiveRecord::Base

  mount_uploader :image, PictureUploader
  validates :image, :presence => true, :on => :create
  attr_accessible :image
 

.....


# encoding: utf-8

class PictureUploader < CarrierWave::Uploader::Base


  # Include RMagick or ImageScience support:
  include CarrierWave::RMagick
.....


the only difference is that i am still running a 1.8.7 ruby with 3.0.9  rails





--
You received this message because you are subscribed to the Google Groups "carrierwave" group.
To post to this group, send email to carri...@googlegroups.com.
To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.




--
Have a nice day!

Alecs
Certified ScrumMaster

P.S. If you are on a list, please don't contact me privately, unless i have allowed to. Further messages will be ignored.

There are no cannibals alive! I have ate the last one yesterday ... 
I am on web:  http://www.alecslupu.ro/
I am on twitter: http://twitter.com/alecslupu
I am on linkedIn: http://www.linkedin.com/in/alecslupu
Tel: (+4)0722 621 280

Bryan

unread,
Jul 12, 2011, 3:10:38 AM7/12/11
to carrierwave
Thanks for the feedback. It works fine if I do it from a new app, its
just happening when trying to integrate it with my existing app. Any
ideas on how to move forward from here?

Alexandru-Emil Lupu

unread,
Jul 12, 2011, 3:32:01 AM7/12/11
to carri...@googlegroups.com
Well ... do you have the "config/initializers/carrierwave.rb" ?
also ... does your config/environment.rb  contains
require File.expand_path('../application', __FILE__)

I am suspecting that your uploader file is not loaded / required ... can you add an extra
require 'app/uploaders/image_uploader'

before

class Game < ActiveRecord::Base
...

A


--
You received this message because you are subscribed to the Google Groups "carrierwave" group.
To post to this group, send email to carri...@googlegroups.com.
To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.

Bryan

unread,
Jul 12, 2011, 3:36:28 AM7/12/11
to carrierwave
I have tried with and without the config file. My environments.rb
file does contain that line. When adding the require to game.rb, I
get the following error:

=> Booting WEBrick
=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:304:in `rescue in depend_on': No such
file to load -- app/uploaders/image_uploader (LoadError)
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:299:in `depend_on'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:216:in `require_dependency'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:46:in `block (2 levels) in <top
(required)>'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:45:in `each'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:45:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:47:in `class_eval'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:47:in `configure'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environments/development.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:239:in `require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:239:in `block in require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:225:in `block in load_dependency'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:596:in `new_constants_in'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:225:in `load_dependency'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:239:in `require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application/bootstrap.rb:11:in `block in <module:Bootstrap>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:25:in `instance_exec'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:25:in `run'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:50:in `block in run_initializers'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:49:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/initializable.rb:49:in `run_initializers'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:134:in `initialize!'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/
rails/application.rb:77:in `method_missing'
from /home/bryanrogers/Desktop/digitalAugment/da-bv-rails/config/
environment.rb:5:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:239:in `require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:239:in `block in require'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:225:in `block in load_dependency'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:596:in `new_constants_in'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:225:in `load_dependency'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/
active_support/dependencies.rb:239:in `require'

Alexandru-Emil Lupu

unread,
Jul 12, 2011, 3:52:13 AM7/12/11
to carri...@googlegroups.com
I might have wrote the require path wrong.. .

Man, I don't have more ideas, try to get that path right.
Unfortunately i am a rails noob :-s (1 month rails experience developing more than 1 hour per day :( )

Alecs

--
You received this message because you are subscribed to the Google Groups "carrierwave" group.
To post to this group, send email to carri...@googlegroups.com.
To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.

Bryan

unread,
Jul 12, 2011, 3:58:47 AM7/12/11
to carrierwave
Ok, well thanks for your help. I'll see if someone has anything to
add tomorrow.

Bryan

unread,
Jul 12, 2011, 12:10:43 PM7/12/11
to carrierwave
Just as an FYI, I installed 0.5.6 with no change. Thanks.

Trevor Turk

unread,
Jul 12, 2011, 3:31:56 PM7/12/11
to carri...@googlegroups.com
Hop on this issue and we'll try to sort it out:

Bryan

unread,
Jul 12, 2011, 4:48:44 PM7/12/11
to carri...@googlegroups.com
Thanks.  I'm posting as bryanrogers on GitHub.
Reply all
Reply to author
Forward
0 new messages