Skip to content

Instantly share code, notes, and snippets.

@captproton
Created October 1, 2009 19:55
Show Gist options
  • Select an option

  • Save captproton/199199 to your computer and use it in GitHub Desktop.

Select an option

Save captproton/199199 to your computer and use it in GitHub Desktop.
##Why do I get this errror?
## Done in console
@group = Group.create(:name => 'admin', :description => 'admin role', :context
@member=User.first
>> @member.groups << @group
NoMethodError: undefined method `groups' for #<User:0x24b641c>
from .../vendor/rails/activerecord/lib/active_record/attribute_methods.rb:260:in `method_missing'
from (irb):8
##Commands that supposedly work:
@group = Group.create(:name => 'admin', :description => 'admin role', :context => 'role')
@member.groups << @group
@member.roles => [:admin]
## Models
#class Group < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
end
#class User < ActiveRecord::Base
acts_as_authentic
acts_as_tagger
has_many :documents
has_many :articles
has_many :memberships
...
end
#class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :group
attr_accessible :user_id, :group_id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment