Skip to content

Instantly share code, notes, and snippets.

@ngw
Created February 1, 2011 21:05
Show Gist options
  • Save ngw/8533b213586d4a2bc257 to your computer and use it in GitHub Desktop.
Save ngw/8533b213586d4a2bc257 to your computer and use it in GitHub Desktop.
class User
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Slug
devise :token_authenticatable, :invitable, :rememberable, :trackable, :validatable
attr_protected :_id
accepts_nested_attributes_for :authentications
field :subdomain, :type => String, :index => true
field :email, :type => String, :index => true
field :nickname, :type => String
field :given_name, :type => String
field :family_name, :type => String
field :location, :type => String, :index => true
field :gender, :type => String
field :url, :type => String
field :birthday, :type => Date
field :created_at, :type => DateTime, :index => true
field :updated_at, :type => DateTime, :index => true
slug :nickname, :index => true, :permanent => true
validates_presence_of :nickname, :email, :subdomain, :authorizations
validates_uniqueness_of :nickname, :email, :subdomain
validates_associated :authorizations
end
ruby-1.9.2-p136 :105 > u = User.new :email => 'test@test.com', :subdomain => 'test', :nickname => 'url unfriendly'
=> #<User _id: 4d4875024fcb0637d0000011, created_at: nil, updated_at: nil, authentication_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, subdomain: "test", email: "test@test.com", nickname: "url unfriendly", given_name: nil, family_name: nil, location: nil, gender: nil, url: nil, birthday: nil, slug: nil>
ruby-1.9.2-p136 :106 > a = Authorization.new :uid => '23', :provider => 'sad', :secret => 'sadsjkhk', :token => 'sajkdhskj'
=> #<Authorization _id: 4d48750d4fcb0637d0000012, created_at: nil, updated_at: nil, provider: "sad", uid: "23", token: "sajkdhskj", secret: "sadsjkhk", url: nil, user_id: nil>
ruby-1.9.2-p136 :107 > u.authorizations << a
=> [#<Authorization _id: 4d48750d4fcb0637d0000012, created_at: nil, updated_at: nil, provider: "sad", uid: "23", token: "sajkdhskj", secret: "sadsjkhk", url: nil, user_id: BSON::ObjectId('4d4875024fcb0637d0000011')>]
ruby-1.9.2-p136 :108 > u.save
=> true
ruby-1.9.2-p136 :109 > u.valid?
=> true
ruby-1.9.2-p136 :110 > u.nickname
=> "url unfriendly"
ruby-1.9.2-p136 :111 > User.last.nickname
=> "url unfriendly"
ruby-1.9.2-p136 :112 > User.last.nickname.to_param
=> "url unfriendly"
gem 'rails', '3.0.3'
gem 'unicorn'
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid'
gem 'mongoid_slug', :require => 'mongoid/slug'
gem 'bson_ext'
gem 'devise'
gem 'omniauth', :git => 'git://github.com/intridea/omniauth.git'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment