This file contains 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 ApplicationRecord < ActiveRecord::Base | |
attr_writer :created_moments_ago | |
def created_moments_ago? | |
@created_moments_ago | |
end | |
def self.create_or_take! | |
where(block_given? && yield).crumby_create! | |
rescue ActiveRecord::RecordNotUnique |
This file contains 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
# app/models/equipment.rb | |
class Equipment < ApplicationRecord | |
has_many :requests | |
has_many :customers, through: :requests | |
validates :brand, presence: true | |
validates :model, presence: true | |
validates :equipment_type, presence: true | |
validates :serial_no, presence: true |
This file contains 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
rails generate model User first_name:string last_name:string email:string | |
rails generate Profile tagline user:references | |
rails db:migrate | |
User.create({name: 'Danilo Velozo', email: '[email protected]', password: '12345', password_confirmation: '12345'}) | |
Profile.create(tagline: 'My Awesome Profile', user_id: User.first.id) | |
# Or |