Skip to content

Instantly share code, notes, and snippets.

@ZackMattor
Created April 23, 2013 20:11
Show Gist options
  • Select an option

  • Save ZackMattor/5446982 to your computer and use it in GitHub Desktop.

Select an option

Save ZackMattor/5446982 to your computer and use it in GitHub Desktop.
class CreateProjectUsers < ActiveRecord::Migration
def change
create_table :project_users do |t|
t.integer :user_id
t.integer :project_id
t.timestamps
end
add_index :project_users, [ :user_id, :project_id], unique: true
end
end
class Project < ActiveRecord::Base
attr_accessible :author_id, :description, :name
has_and_belongs_to_many :users
end
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_and_belongs_to_many :roles
has_many :blogPosts
def role?(role)
return true
# roles.include? role.to_s
end
def to_s
email
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment