Skip to content
chris edited this page Jul 19, 2023 · 3 revisions

Contents

General Notes

  • rails follows the convention over configuration software design paradigm.
  • rails v4.0 requires ruby >= 1.9.2
A pictorial πŸ“Έ diagram explaining rails

rails > Naming Conventions

  • model name is singular, ie. mr_fancy_pant.rb
  • database table name is plural, ie. mr_fancy_pants
  • migration files should follow the plural naming convention, ie. 20140528053443_create_mr_fancy_pants.rb

Benchmarking

Benchmarking RVM Ruby 2.3.1, rails 4.2.x, execjs & rubyracer
Benchmarking RVM Ruby 2.5.3, rails 4.2.10, Node.js

Rails Notes

  • rails defaults to the system encoding which is UTF-8 the majority of the time.
  • Generally it's a good idea to check and make sure databases have been created before trying to deploy a rails app.

rails > working with erb

to put a multiline comment in a .html.erb file

<% if false %>
  multiline
  comment
  in an erb template file
<% end %>
<%-# single line erb comment -%>

rails version 5 Notes

Rails version 5 has migrated from using rake to rails

Useful commands

To install rails with no documentation

gem install rails --no-ri --no-rdoc

rails > Working with Databases

Three types of database relationship asociations

  1. one-to-one
  2. one-to-many
  3. many-to-many

To test the database connection

bundle exec rake db:schema:dump

To undo all migrations applied to a database

⚠️ All data in the database will be dropped, ie. deleted

bundle exec rake db:migrate VERSION=0

To get a list of all the migrations and their status

bundle exec rake db:migrate:status

To reset the database to its starting point

bundle exec rake db:migrate:reset

rails > working with database migrations

To create / setup databases for a rails version 4 app

rake db:create:all

To run all the migrations for the DB

rake db:migrate

To show the status of the migrations, ie. whether they have been applied or not

rake db:migrate:status

To remove a migration file

rails destroy migration 20140528053443_create_mr_fancy_pants.rb

To rollback one migration

rake db:rollback

To clear the contents of the DB

rake db:reset

To create a rails project without a test suite

rails new [project_name] -T

To delete a model

rails destroy model [model_name]

General rails 5 Notes

rails 5 requires Ruby >= 2.2.2 the rails command replaces rake in rails 5

  • The development server switched from WEBrick to Puma

Definitions

  • ActionCable is a framework for working with WebSockets

ActionCable

JSON API

To create a new rails app that acts as a JSON API

rails new mr_fancy_pants_api --api

Useful Links

General Useful Links

bootstrap

To remove border radius from a navbar, see

file attachments

🚬blog post > rolling your own file attachment

devise & omniauth

Authentication

API

turbolinks

google analytics

IRC

To show a an IRC users activity in the #rubyonrails channel on freenode

http://logs.ryanbigg.com/p/$USER/activity