Guest User

Untitled

a guest
Aug 13th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #Setup
  2. Rails 3.0.0
  3. Ruby 1.9.2
  4. Mysql
  5.  
  6. #Model
  7. class User < ActiveRecord::Base
  8. # Include default devise modules. Others available are:
  9. # :token_authenticatable, :confirmable, :lockable and :timeoutable
  10. devise :database_authenticatable, :registerable,
  11. :recoverable, :rememberable, :trackable, :validatable
  12.  
  13. # Setup accessible (or protected) attributes for your model
  14. attr_accessible :email, :password, :password_confirmation, :remember_me
  15. has_many :sites
  16.  
  17. def admin?
  18. return self.is_admin
  19. end
  20. end
  21.  
  22. #Schema
  23. create_table "users", :force => true do |t|
  24. t.string "email", :default => "", :null => false
  25. t.string "encrypted_password", :limit => 128, :default => "", :null => false
  26. t.string "password_salt", :default => "", :null => false
  27. t.string "reset_password_token"
  28. t.string "remember_token"
  29. t.datetime "remember_created_at"
  30. t.integer "sign_in_count", :default => 0
  31. t.datetime "current_sign_in_at"
  32. t.datetime "last_sign_in_at"
  33. t.string "current_sign_in_ip"
  34. t.string "last_sign_in_ip"
  35. t.datetime "created_at"
  36. t.datetime "updated_at"
  37. t.boolean "is_admin", :default => false, :null => false
  38. end
  39.  
  40. #Controller
  41.  
  42.  
  43. #Use
  44. irb(main):001:0> user = User.create(:email => "test@test.com", :password => "testtest", :password_confirmation => "testtest", :is_admin => true)
  45. => #<User id: 1, email: "test@test.com", encrypted_password: "$2a$10$69uG7Q57UWwfyR.dMbt9.ed.JfFzTLScqqv6C1UG8Epn...", password_salt: "$2a$10$69uG7Q57UWwfyR.dMbt9.e", reset_password_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, created_at: "2010-10-16 00:57:44", updated_at: "2010-10-16 00:57:44", is_admin: false>
Add Comment
Please, Sign In to add comment