all Flashcards
what is a web framework
give baseline tools such as routing, asset management, etc so you don’t have to start from stratch
what is the MVC framework
Model - View - Controller
what is an opinionated framework
convention over configuation . have a certain way to set up organization
what goes in the app file
models, view, controllers
what goes in config file
routes
what goes in db file
migration files, schema, seed
syntax for route in rails
get “/route”, to “route#index”
syntax for controller
class FileController < ApplicationController
def index
end
end
what is the Model
like a chef. communicates with database via Active Record
what is the Controller
like the waiter. transmits data from user to the models and back to the user to view
what is the view
like the table. where date is visible to user
why use rails generators
less time consuming
help prevent errors and debug
types of generator
rails g model - create model
rails g controller - create controller
rails g migration - create new table
rails g resources - create model, controller, migration, view folder and routes
syntax for rails generator
rails g model TableName column1 column2:integer
what does rail generator default to for type
string
what do you run to save a migration
rails db:migrate
syntax for seed
Table.create(column: “data”, column: “data”)
what is the basic HTTP work flow
client request to server (fetch)
request goes to server where router interpret request and sends message to controller to map route
controller uses model to access database
controller uses data to render view (HTML or JSON)
server returns response
Which name is singular and which is plural in model and controller names
model = singular
controller = plural
what is rails is like binding.pry
byebug
Process for Dynamic Routes
routes that include parameter
routes send to controller
get instance associated with params
static routes
always have fixed routes (/user)
dynamic routes
render different data based on the parameters (/user/:id)
what does the code in controller look like for dynamic routes
def show
user = user.find(param [:id])
render json: user
end
what do static routes look like in controller
def index
users = user.all
render json: users
end