This is the finance-tracker application from the Complete Ruby on Rails Developer course. Click the link to see it in action Finance Tracker.
Name | Version |
---|---|
Ruby | 2.6.6p146 |
Rails | 5.2.1 |
bcrypt | 3.1.7 |
Create a new rails project
rails new <project-name>
When modifying the columns on models in the DB, run:
rails generate migration name_of_migration_file
Then specify the changes the newly created migration file, afterwards, run:
rails db:migrate
All available routes in Rails can be viewed by running:
rails routes --expanded
Run the console with:
rails c
Run the server with:
rails s
Run the test suite with:
rails test
Update a boolean attribute on an instance with toggle:
user.toggle!(:admin)
Enable table views in the console (in the console)
Hirb.enable
The encrypted credentials for the application are saved in config/credentials.yml.enc. To view/edit these credentials run:
EDITOR="code --wait" rails credentials:edit
To access credentials in the code (e.g. AWS's Access Key), use:
Rails.application.credentials.aws[:access_key_id]
New Model + DB migration file (e.g. User with attributes name and height)
rails generate model User name:string height:decimal
Prefill DB with mock data programatically (update db/migrate/seeds.rb file first):
rails db:seed
New Controller (e.g. messages)
rails generate controller messages <action>
Controller test file:
rails generate test_unit:scaffold name_of_model
Undo a Controller generation:
rails destroy controller messages
New Channel (e.g. chatroom)
rails generate channel chatroom
New Resource (e.g. many-to-many relationship between 2 models)
rails g resource UserStock user:references stock:references
Ensure that a production DB is in place. Add this to your Gemfile:
group :production do
gem 'pg'
end
Handles various platforms in production, run this command to update your Gemfile.lock:
bundle lock --add-platform x86_64-linux
Ensure that you're logged into Heroku. The CLI will link you to a page to use your authenticator app on:
heroku login
To create a new production version of your app hosted in Heroku, use:
heroku create
To rename your application in Heroku, run:
heroku rename <new_name_of_application>
Ensure that the main branch is up-to-date in Github and that all gems are installed, then update the main branch in Heroku:
git push heroku <main/master>
Then run any pending migrations in Heroku
heroku run rails db:migrate
Upload your master.key to Heroku (secrets)
heroku config:set RAILS_MASTER_KEY=<your_master.key_value>
Afterwards, Production should be updated and is ready to view
heroku open