Created
May 28, 2012 18:15
-
-
Save cyberoctopi/2820389 to your computer and use it in GitHub Desktop.
user fields
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 | |
| include Mongoid::Document | |
| before_save :copy_to_last_weight | |
| attr_accessible :nickname, :first_name, :last_name, :email, :weight, :last_weight, :height, :password, :password_confirmation, :remember_me | |
| # Include default devise modules. Others available are: | |
| # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable | |
| devise :database_authenticatable, :registerable, | |
| :recoverable, :rememberable, :trackable, :validatable | |
| validates_presence_of :nickname, :first_name, :last_name, :weight, :height, :goal | |
| validates_uniqueness_of :nickname, :email, :case_sensitive => false | |
| ## User additional fields | |
| field :nickname, :type => String | |
| field :first_name, :type => String | |
| field :last_name, :type => String | |
| field :website, :type => String | |
| field :weight, :type => Integer | |
| field :last_weight, :type => Integer | |
| field :height, :type => String | |
| field :bodyfat, :type => String | |
| field :right_arm, :type => Float | |
| field :left_arm, :type => Float | |
| field :waist, :type => String | |
| field :right_leg, :type => String | |
| field :left_leg, :type => String | |
| field :goal, :type => String, :default => "Lose Weight" | |
| ## trainer id - client enters trainers ID and gets drawn into the trainers group | |
| field :trainer, :type => Boolean, :default => "false" | |
| field :trainer_moderater, :type => Boolean, :default => "false" | |
| ## Relationships | |
| has_many :routines | |
| has_many :workouts | |
| embeds_many :conditions | |
| ## Database authenticatable | |
| field :email, :type => String, :null => false, :default => "" | |
| field :encrypted_password, :type => String, :null => false, :default => "" | |
| ## Recoverable | |
| field :reset_password_token, :type => String | |
| field :reset_password_sent_at, :type => Time | |
| ## Rememberable | |
| field :remember_created_at, :type => Time | |
| ## Trackable | |
| field :sign_in_count, :type => Integer, :default => 0 | |
| field :current_sign_in_at, :type => Time | |
| field :last_sign_in_at, :type => Time | |
| field :current_sign_in_ip, :type => String | |
| field :last_sign_in_ip, :type => String | |
| ## Encryptable | |
| # field :password_salt, :type => String | |
| ## Confirmable | |
| # field :confirmation_token, :type => String | |
| # field :confirmed_at, :type => Time | |
| # field :confirmation_sent_at, :type => Time | |
| # field :unconfirmed_email, :type => String # Only if using reconfirmable | |
| ## Lockable | |
| # field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts | |
| # field :unlock_token, :type => String # Only if unlock strategy is :email or :both | |
| # field :locked_at, :type => Time | |
| ## Token authenticatable | |
| # field :authentication_token, :type => String | |
| def self.find_by_nickname(nickname) | |
| User.where(nickname = "#{nickname}") | |
| end | |
| def copy_to_last_weight | |
| self.last_weight = weight | |
| end | |
| end | |
| class Condition | |
| include Mongoid::Document | |
| field :condition, :type => String | |
| ## Relationships | |
| embedded_in :user | |
| 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
| ## Make a way for users to look through ready made default workouts and ATTACH | |
| ## to their profile | |
| class Routine | |
| include Mongoid::Document | |
| field :name, :type => String, :default => "Routine" | |
| field :level, :type => String, :default => "Intermediate" | |
| field :day_count, :type => Integer, :default => 5 | |
| field :description, :type => Integer | |
| field :start_date, :type => DateTime | |
| field :end_date, :type => DateTime | |
| field :completed, :type => Boolean | |
| ## Relationships | |
| belongs_to :user | |
| has_many :workouts | |
| end | |
| class Workout | |
| include Mongoid::Document | |
| attr_accessible :name, :trainer, :activities_attributes | |
| field :name, :type => String, :default => "Cardio" | |
| field :activity_id, :type => Integer | |
| field :trainer, :type => Boolean | |
| field :commited, :type => Boolean | |
| ## Relationships | |
| belongs_to :user | |
| belongs_to :routine | |
| has_many :activities, :autosave => true, :dependent => :destroy | |
| accepts_nested_attributes_for :activities, :reject_if => :all_blank, | |
| :allow_destroy => true | |
| def creater_by_trainer | |
| if current_user.trainer == True | |
| self.workout.trainer = True | |
| end | |
| end | |
| end | |
| class Activity | |
| include Mongoid::Document | |
| attr_accessible :name, :weight, :sets, :reps | |
| field :name, :type => String | |
| field :type, :type => String | |
| field :weight, :type => Integer | |
| field :sets, :type => Integer | |
| field :reps, :type => Integer | |
| field :notes, :type => String | |
| #Day | |
| #time duration | |
| ## Relationships | |
| belongs_to :workout | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment