DEV Community

Cover image for Rails Quick-Ref VOL. 1
Kaleb
Kaleb

Posted on • Updated on

Rails Quick-Ref VOL. 1

What is rails?

Ruby on rails is technically a full-stack framework built on top of ruby. Meaning that it has the tools to build both front and backend apps.

Why use rails?

Rails is best suited for quickly creating an API with custom logic within a MVC development structure. The generators allow you to quickly setup all files from the command line and connects them via Active Record

Getting into it:

  1. add rails to your gem bundle, with gem install rails
  2. use rails new my-app or bootstrap from chosen directory
  3. run your rails server with rails server
  4. build your app From here you can everything from a full stack app to a simple API and everything in-between.

Helpful Commands

  • rails s
    start the server of current directory

  • rails db:seed
    populate the database from seed file

  • rails db:migrate
    update the schema file from the migration files

  • rails new project-name options
    ex: rails new Hacker-API
    create a new rails directory

  • rails d <name of generator> <class_name>
    ex: rails d resource Shop
    delete a specified generator

  • Rails g -lists the generators

  • rails g <generator> <model name> <attribute> <options> <flag>

Generators

  • migration: creates a migration
  • model: creates a migration and model
  • controller: creates a migration, model, and controller
  • resource: creates migration, model, controller, and routes These generators can be found in your config folder

attribute

Here we define an attribute of our model:
attrname:string
name:DATATYPE
with the attribute name and its data type.

Options

  • --no-test-framework exclude the test file

helpful links:

What's new with Ruby on Rails 7
sauce
more sauce
Ruby on rails Wikepedia

Top comments (0)