Rails Project about a Bank

class Userhas_many :credit_cards, class_name: :Card, as: :card_ownerhas_many :owned_merch, class_name: :Merchandise, as: :ownerhas_many :merchandiseshas_many :loans, through: :merchandises, source: :account
class Account
belongs_to :user, optional: true #if owned through join table as loan and not directly as savings or checkingvalidates_presence_of :user, if: :user_id_present?has_many :cards, as: :card_ownerhas_many :merchandiseshas_many :loanees, through: :merchandises, source: :user
#in gemfile require 'devise'#in terminal runbundle install run rails g devise:install 
#inside devise.rb I putconfig.omniauth :facebook, Rails.application.credentials.facebook[:key], Rails.application.credentials.facebook[:secret], 
callback_url: "http://localhost:3000/users/auth/facebook/callback"
#to setup the Rails.application.credentials which stores our key and secret safe, without saving to github#in terminal inside the project folder if using Unix or Linux, nano is command line text editor that will give us access to credentials.yml.enc which is an encrypted file.

EDITOR="nano" rails credentials:edit
#here we store our key and secret from facebook for devsfacebook:
key: bunchonumbers
secret: numbersandlettersalot
#and to access encrypted secretsRails.application.credentials.facebook[:key] comes into play in the devise.rb file
# I used nested routingresources :users, only: [:new, :create, :show] do
resources :accounts, only: [:new, :create, :index, :show, :edit, :update]
resources :cards, only: [:show, :edit, :update]
get '/total_debt', to: 'site#total_debt'
#which helped with validationsclass Accountscope :loans, -> { where(name: :loan) }scope :saving_and_checking, -> { where('name = ? or name = ?', 'checking', 'savings')}scope :added_up, lambda { where("name = ?", 'loan').sum(:balance)}class Cardscope :added_up, lambda {where("card_type=?",'Credit').sum(:balance)}
number_to_currency(1234567890.50)=> $1,234,567,890.50



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store