Habtm many-to-many relationship problem attribute_methods.rb

Hi,

I have a many-to-many relationship between: registrations and groups
(properly setup on each side with has_and_belongs_to_many)

so I do this in the console:

reg = Registration.find(:first)
grp = Group.find(:first)

grp.registrations list me the registrations’ attributes linked with
the group in question

reg.groups returns me:

NoMethodError: undefined method groups' for #<Registration:0x3164718> from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/attribute_methods.rb:256:inmethod_missing’
from (irb):XX

where XX started around 10 I think and kept augmenting each time I ran
“reg.groups”

I can’t figure out what is happening to get this message…
registrations and groups are identically setup to what I can see…

thanks if anyone can bring me any clue!

PS. I’m using restful_authentication and restful_acl, but it shouldn’t
give any problem here…

Actually, some model names are in french so I translated, so it could
make more sens … but registration is inscription and groups are
periodes in the above example…

some code in the models are temporary, just so that I can debug more
easily.
Here are models and migrations

#########################################
class Inscription < ActiveRecord::Base

has_and_belongs_to_many :periodes
belongs_to :user

#restful_acl part - supposed to work fine###############
def is_updatable_by(user)
current_user.is_admin?
end

def is_deletable_by(user)
current_user.is_admin?
end

def self.is_readable_by(user, object = nil)
true
#current_user.is_admin?
end

def self.is_creatable_by(user)
current_user.is_admin?
#user != nil #Ensure the user is logged in

end

end

######################################
class Periode < ActiveRecord::Base

has_and_belongs_to_many :inscriptions

belongs_to :course
belongs_to :prof

def is_updatable_by(user)
current_user.is_admin?
end

def is_deletable_by(user)
current_user.is_admin?
end

def self.is_readable_by(user, object = nil)
true
#user != nil #Ensure the user is logged in
end

def self.is_creatable_by(user)
current_user.is_admin?
#user != nil #Ensure the user is logged in

end

end

other models
##########
user has_many :inscriptions
prof has_many :periodes
course has_many :periodes

##############################################
MIGRATIONS
#############################################

class CreatePeriodes < ActiveRecord::Migration
def self.up
create_table :periodes do |t|
t.integer :course_id
t.integer :prof_id

  t.timestamps
end

end

def self.down
drop_table :periodes
end
end

#################
class CreateInscriptionsPeriodes < ActiveRecord::Migration
def self.up
create_table :inscriptions_periodes, :id => false do |t|
t.integer :inscription_id
t.integer :periode_id

  t.timestamps
end

#add_index :inscriptions_periodes, [:inscription_id, :periode_id]

end

def self.down
drop_table :inscriptions_periodes
end
end

class CreateInscriptions < ActiveRecord::Migration
def self.up
create_table :inscriptions do |t|
t.integer :user_id

  t.timestamps
end

end

def self.down
drop_table :inscriptions
end
end

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