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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---