# I got an uninitialized constant error, help!

**URL:** <https://www.ruby-forum.com/t/i-got-an-uninitialized-constant-error-help/134755>\
**Category:** Rails\
**Created:** [April 14, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/i-got-an-uninitialized-constant-error-help/134755 "2008-04-14T21:10:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![icecode](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/848f3c/32.png) [@icecode](https://www.ruby-forum.com/u/icecode)\
**Post date:** [April 14, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/i-got-an-uninitialized-constant-error-help/134755/1 "2008-04-14T21:10:20Z")

</div>

hey guys, i am new to rails, so please be nice to me if i ask stupid  
questions.

I ran into this problem as I try to play with many to many  
association.

I have three objects,

Category  
has\_many :artist, :through =\> artist\_category  
has\_many :artist\_category  
Artist  
has\_many :category, :through =\>artist\_category  
hash\_many :artist\_category  
attr\_accessor :category\_ids

after\_save :update\_category

def update\_category  
unless category\_ids.null?  
self.artist\_category.each do |m|  
m.destory unless category\_ids.include?(m.category\_id.to\_s)  
category\_ids.delete(m.category\_id.to\_s)  
end

```
    category_ids.each do |g|
      self.category_artist.create(:category_id => g) unless

```

g.blank?  
end  
reload  
end  
end

Artist\_Category  
belongs\_to: category  
belongs\_to: artist

# ============ on the artists\_controller, i have new and create method

def new  
@artists = Artists.new  
@category = Category.find(params[:category\_id])  
end

def create  
@artists = Artists.new(params[:artists])  
@category = Category.find(params[:category\_ids])  
@artists.category\_ids=@category.id  
logger.debug(“saving artist name=#{@artists.name} to  
category\_id=#{@category.id}”)  
respond\_to do |format|  
Artist.transaction do  
if @artists.save!  
flash[:notice] = ‘Artists was successfully created.’  
format.html { redirect\_to(@artists) }  
format.xml { render :xml =\> @artists, :status  
=\> :created, :location =\> @artists }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @artists.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end  
end

=========== i got following error ================  
uninitialized constant ArtistsController::Artist

RAILS\_ROOT: C:/development/projects/  
Application Trace | Framework Trace | Full Trace

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active\_support/  
dependencies.rb:478:in `const_missing' app/controllers/artists_controller.rb:47:in`create’  
app/controllers/artists\_controller.rb:46:in `create' -e:1:in`load’  
-e:1

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active\_support/  
dependencies.rb:478:in `const_missing' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ mime_responds.rb:106:in`call’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
mime\_responds.rb:106:in `respond_to' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ base.rb:1158:in`send’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
base.rb:1158:in `perform_action_without_filters' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ filters.rb:697:in`call\_filters’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
filters.rb:689:in `perform_action_without_benchmark' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ benchmarking.rb:68:in`perform\_action\_without\_rescue’

anybody know why i am getting error above? thanks in advance

---

<div class="post-metadata">

**Author:** ![icecode](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/848f3c/32.png) [@icecode](https://www.ruby-forum.com/u/icecode)\
**Post date:** [April 14, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/i-got-an-uninitialized-constant-error-help/134755/2 "2008-04-14T23:51:59Z")

</div>

On Apr 14, 8:09 pm, icecode [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hey guys, i am new to rails, so please be nice to me if i ask stupid  
> questions.
> 
> I ran into this problem as I try to play with many to many  
> association.
> 
> I have three objects,

You’re mixing and matching :artist, :artists, Artists, Artist. Your  
has\_manys should be :artists and when you’re talking about the class,  
then it should always be Artist (which should be in artist.rb)

Fred
