Created
June 2, 2013 02:37
-
-
Save ZackMattor/5692411 to your computer and use it in GitHub Desktop.
Double relationship between users and projects. Projects have many users that can work on them, and projects have one user who is the original creator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Project < ActiveRecord::Base | |
attr_accessible :author, :description, :name, :user_ids | |
has_and_belongs_to_many :users | |
belongs_to :author, :class_name => "User", :foreign_key => "author" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Include default devise modules. Others available are: | |
# :token_authenticatable, :confirmable, | |
# :lockable, :timeoutable and :omniauthable | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable | |
# Setup accessible (or protected) attributes for your model | |
attr_accessible :email, :password, :password_confirmation, :remember_me | |
# attr_accessible :title, :body | |
has_many :roles | |
has_and_belongs_to_many :roles | |
has_many :projects, through: :ProjectUser | |
has_many :projects, :class_name => "Project", :foreign_key => "author" | |
has_many :projects | |
has_many :blogPosts | |
def role?(role) | |
return true | |
# roles.include? role.to_s | |
end | |
def to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment