I got an uninitialized constant error, help!

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])
@[email protected]
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:increate’
app/controllers/artists_controller.rb:46:in create' -e:1:inload’
-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:incall’
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:insend’
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:incall_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:inperform_action_without_rescue’

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

On Apr 14, 8:09 pm, icecode [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs