Created
June 29, 2015 09:50
-
-
Save soilforlifeforms/90785ed2ab92b6a0150c to your computer and use it in GitHub Desktop.
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 AssistantTrainer < User | |
| belongs_to :trainer | |
| 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
| 2.1.2 :035 > trainer | |
| => #<Trainer id: 3, email: "at2@at.com", encrypted_password: "$2a$10$ASt34cSOixmCw0JWe8BRQu8BhQSmK6WaAeqtzuDKDB....", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 2, current_sign_in_at: "2015-06-22 09:39:35", last_sign_in_at: "2015-06-19 06:57:11", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-06-19 06:57:11", updated_at: "2015-06-22 09:39:35", name: "at2", role: 0, type: "Trainer", trainer_id: nil> | |
| 2.1.2 :036 > at | |
| => #<AssistantTrainer id: 1, email: "trainer@trainer.com", encrypted_password: "$2a$10$s29lmJAZOMFLXUWbcDQDWeYBf/dyihdUVkRmHEr4kMx...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 2, current_sign_in_at: "2015-06-19 06:57:40", last_sign_in_at: "2015-06-19 06:55:54", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-06-19 06:55:53", updated_at: "2015-06-22 08:58:14", name: "Trainer", role: 0, type: "AssistantTrainer", trainer_id: 3> | |
| 2.1.2 :037 > new_at | |
| => #<User id: 4, email: "newat@sfl.co.za", encrypted_password: "$2a$10$7.xuBvnvEgkFEyFLEpBDmuxOWyPV43aCMNAuZvGzIRX...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-06-29 09:18:04", last_sign_in_at: "2015-06-29 09:18:04", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-06-29 09:18:03", updated_at: "2015-06-29 09:32:31", name: nil, role: 0, type: "AssistantTrainer", trainer_id: 3> | |
| 2.1.2 :038 > trainer.assistant_trainers | |
| => #<ActiveRecord::Associations::CollectionProxy [#<AssistantTrainer id: 1, email: "trainer@trainer.com", encrypted_password: "$2a$10$s29lmJAZOMFLXUWbcDQDWeYBf/dyihdUVkRmHEr4kMx...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 2, current_sign_in_at: "2015-06-19 06:57:40", last_sign_in_at: "2015-06-19 06:55:54", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-06-19 06:55:53", updated_at: "2015-06-22 08:58:14", name: "Trainer", role: 0, type: "AssistantTrainer", trainer_id: 3>, #<AssistantTrainer id: 4, email: "newat@sfl.co.za", encrypted_password: "$2a$10$7.xuBvnvEgkFEyFLEpBDmuxOWyPV43aCMNAuZvGzIRX...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-06-29 09:18:04", last_sign_in_at: "2015-06-29 09:18:04", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-06-29 09:18:03", updated_at: "2015-06-29 09:32:31", name: nil, role: 0, type: "AssistantTrainer", trainer_id: 3>]> | |
| 2.1.2 :039 > new_at.groups | |
| Group Load (4.2ms) SELECT "groups".* FROM "groups" WHERE "groups"."user_id" = $1 [["user_id", 4]] | |
| Group Load (4.2ms) SELECT "groups".* FROM "groups" WHERE "groups"."user_id" = $1 [["user_id", 4]] | |
| => #<ActiveRecord::Associations::CollectionProxy []> | |
| 2.1.2 :040 > at.groups | |
| => #<ActiveRecord::Associations::CollectionProxy [#<Group id: 3, group_name: "assistant trainer group", area: nil, user_id: 1, avatar: nil, created_at: "2015-06-29 09:05:51", updated_at: "2015-06-29 09:05:51", group_picture_file_name: nil, group_picture_content_type: nil, group_picture_file_size: nil, group_picture_updated_at: nil>]> | |
| 2.1.2 :042 > trainer.assistant_trainers.each do |t| | |
| 2.1.2 :043 > t.groups | |
| 2.1.2 :044?> end | |
| => [#<AssistantTrainer id: 1, email: "trainer@trainer.com", encrypted_password: "$2a$10$s29lmJAZOMFLXUWbcDQDWeYBf/dyihdUVkRmHEr4kMx...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 2, current_sign_in_at: "2015-06-19 06:57:40", last_sign_in_at: "2015-06-19 06:55:54", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-06-19 06:55:53", updated_at: "2015-06-22 08:58:14", name: "Trainer", role: 0, type: "AssistantTrainer", trainer_id: 3>, #<AssistantTrainer id: 4, email: "newat@sfl.co.za", encrypted_password: "$2a$10$7.xuBvnvEgkFEyFLEpBDmuxOWyPV43aCMNAuZvGzIRX...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-06-29 09:18:04", last_sign_in_at: "2015-06-29 09:18:04", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2015-06-29 09:18:03", updated_at: "2015-06-29 09:32:31", name: nil, role: 0, type: "AssistantTrainer", trainer_id: 3>] | |
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 Trainer < User | |
| has_many :assistant_trainers | |
| 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 | |
| enum role: [:user, :vip, :admin] | |
| after_initialize :set_default_role, :if => :new_record? | |
| #has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png" | |
| #validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/ | |
| has_many :groups | |
| belongs_to :phone_rental | |
| has_many :gardeners, through: :groups | |
| def set_default_role | |
| self.role ||= :user | |
| end | |
| # Include default devise modules. Others available are: | |
| # :confirmable, :lockable, :timeoutable and :omniauthable | |
| devise :database_authenticatable, :registerable, | |
| :recoverable, :rememberable, :trackable, :validatable | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment