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:in `method_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...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
c-a
2008-Jul-02 13:43 UTC
Re: habtm many-to-many relationship problem attribute_methods.rb
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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---