I’d like to be able to use a has_many :through association and treat
the associations as a list but I’m getting this error when I try an
use an acts_as_list method:
NoMethodError: undefined method `move_to_bottom’
I’m using edge rails r6786.
Here are my domain rules:
Activities are things students can do.
Units consists of a sequenced list of Activities.
Activities can be used in many Units.
Here are the associations for these rules:
class Activity < ActiveRecord::Base
has_many :unit_activities
has_many :units, :through => :unit_activities
end
class Unit < ActiveRecord::Base
has_many :unit_activities, :order => :position
has_many :activities, :through => :unit_activities
end
class UnitActivity < ActiveRecord::Base
belongs_to :activity
belongs_to :unit
acts_as_list :scope => :unit_id
end
In he example below in script/console I load in some previously
created activities; make a new unit; and add the activities to the
unit.
activity_crystals = Activity.find_by_name(“Molecular crystals”)
activity_browning = Activity.find_by_name(“Brownian motion”)
activity_mixing = Activity.find_by_name(“Temperature of mixing
water - TEEMSS demo”)
my_unit = Unit.create(:name => “My First Unit”, :description => “A
simple test unit to see if thenew associations work”)
my_unit.activities.push(activity_crystals, activity_browning,
activity_mixing)
my_unit.activities.each { |a| puts “#{a.id}: #{a.name}” }; nil
55: Molecular crystals
42: Brownian motion
25: Temperature of mixing water - TEEMSS demo
Here’s where the error occurs:
my_unit.activities[0].move_to_bottom
NoMethodError: undefined method `move_to_bottom’ for
#Activity:0x34dec54
from
At this point my unit_activities table looks like this:
id activity_id unit_id position
1 55 1 1
2 42 1 2
3 25 1 3