Rails Quick-Ref VOL. 1
Kaleb
Posted on April 5, 2022
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:
- add rails to your gem bundle, with
gem install rails
- use
rails new my-app
or bootstrap from chosen directory - run your rails server with rails server
- 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 directoryrails db:seed
populate the database from seed filerails db:migrate
update the schema file from the migration filesrails new project-name options
ex:rails new Hacker-API
create a new rails directoryrails d <name of generator> <class_name>
ex:rails d resource Shop
delete a specified generatorRails g
-lists the generatorsrails 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
Posted on April 5, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.