Skip to content

Instantly share code, notes, and snippets.

@elffey
Created July 8, 2011 11:24
Show Gist options
  • Save elffey/1071639 to your computer and use it in GitHub Desktop.
Save elffey/1071639 to your computer and use it in GitHub Desktop.
class Profile < ActiveRecord::Base
has_many :profiles_users, :class_name => "ProfilesUsers"
has_many :users, :through => :profiles_users
has_many :admins,
:through => :profiles_users,
:source => :user,
:conditions => ["profiles_users.role = ?", "admin"]
has_many :editors,
:through => :profiles_users,
:source => :user,
:conditions => ["profiles_users.role = ?", "editor"]
...
# would like to be able to do something like this:
@profile.create params[:profile]
@profile.admins << current_user
@profile.editors << another_user
# instead the role field is being left blank
# ideally would also like to be able to do:
@profile.owner = current_user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment