Ruby on Rails Cheat Sheet to Jumpstart Rails Apps

Welcome to this Ruby on Rails cheats sheet that helps you jumpstart your rails apps.

Whether you’re just learning Rails or you’re an experienced Ruby on Rails developer, this cheat sheet will help make your life easier.

General Terminal Commands

  • $ cd [name of folder] – takes you to a new folder within the current directory
  • $ ls – shows you the contents of the folder you are in
  • $ pwd – tells you where in the directory you currently are
  • $ mkdir – creates a new directory
  • command-k – clears the existing commands

Ruby on Rails Terminal Commands

  • $ rails new [name]
    • Creates a new Ruby on Rails app with the name of your choice
    • After running the command, your application is in a folder with the same name you gave the application
    • You cd into that folder.
  • $ rails s or $ rails server
    • runs the rails server on your local server, and enables you to view your app on http://localhost:3000
    • after you run this, open up a new tab in terminal to run other commands
    • ctrl-c closes the server and resets the command line
  • $ rails g scaffold [ModelName] [attribute]:[type]
    • Example: $ rails g scaffold User name:string email:string
    • You can keep listing different attributes that you’d like
  • $ rake db:migrate 
    • After adding a new migration (like by adding a new scaffold, for example), the migration has to be applied to your database
    • This command does the trick to update your database
  • $ rake db:reset – resets the DB
  • $ rake db:rollback – rolls back your last migration to your database
  • $ rake routes – shows all the routes available in your application
  • $ rails g migration [add_columnname_to_tablename columnname:datatype] – use this format to add a new attribute to a model
  • $ rails g migration [rename_name_column_to_username] – use this format to rename an attribute in a model

Gem Terminal Commands

  • $ bundle install
    • After you add a new gem to your Gemfile, run bundle install to install it.
    • Restart your server afterwards
  • $ bundle check – verifies if the dependencies listed in Gemfile are satisfied by currently installed gems

 Useful Gems

  • Devise – authentication
  • CanCanCan – authorization
  • Kaminari – pagination
  • Ransack – scoping, searching, and filtering, and the creation of simple and advanced search forms for Ruby on Rails apps
  • Twitter-bootstrap-rails – frontend development, makes your website look good even if you know very little about web design
  • CarrierWave – user generated files and user uploads ; can use Paperclip gem as an alternative
  • Searchkick – intelligent searching (learns what users look for to provide better results)