I’ve got an application that I’m working on where I have a System model
that I want to add to arbitrary logical Groups (a System can be part of
multiple groups and a Group is made up of one or more Systems).
I’ve got it set up like this:
class Affiliation < ActiveRecord::Base
belongs_to :systems, :class_name => ‘system’, :foreign_key =>
‘system_id’
belongs_to :groups, :class_name => ‘group’, :foreign_key => ‘group_id’
end
class Group < ActiveRecord::Base
has_many :affiliations, :dependent => true
has_many :systems, :through => :affiliations
end
class System < ActiveRecord::Base
has_many :affiliations, :dependent => true
has_many :groups, :through => :affiliations
end
when I do this (in my add action in my GroupsController:
group = Group.find(params[:group], :limit => 1)
system = System.find(params[:system], :limit => 1)
group.systems << system
I get an ArgumentError: wrong number of arguments.
the stack trace is:
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1360:in
system' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1360:in
compute_type’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:125:in
send' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:125:in
klass’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/has_many_through_association.rb:115:in
find_target' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/association_proxy.rb:131:in
load_target’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/association_proxy.rb:122:in
method_missing' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations/has_many_through_association.rb:108:in
method_missing’
#{RAILS_ROOT}/app/controllers/groups_controller.rb:20:in `add’
any ideas?
Thanks!
…spike