Basics Flashcards
What is the request/response cycle?
The browser makes a request for the URL http://localhost:3000
The request hits the Rails router in config/routes.rb.
The router recognizes the URL and sends the request to the controller.
The controller receives the request and processes it.
The controller passes the request to the view.
The view renders the page as HTML.
The controller sends the HTML back to the browser for you to see.
How do you make a controller?
rails g controller Name
What is the workflow when making a rails app?
1) Generate a new rails app = rails new App_name
2) Generate a controller and add an action = rails g controller action
3) Create a route that maps a URL to a controller action
4) Create a view with HTML and CSS
5) Check it in the localhost with rails s
How do the model and database fit into the request/response cycle?
When the controller action receives the request it send for the data to the model which in turn brings the data from the database and sends it back to the action.
How do you create a model?
1) rails g model Name title:string description:text price:integer
2) run rails db:migrate
3) rails db:seed
What does the model do?
It represents a table in the database
What is a migration?
A migration is a way to update the database.
What does the migration file contain?
1) It contains the change method which tells rails what change to make in the database
2) Inside the change method, we have the create_table method which creates a new table in the database for storing.
3) Inside the create table we have a title which creates a string and so on.
4) We also have the timestamps which automatically creates a created_at and updated_at
What does rails db:seed do?
The command seeds the database with sample data from db/seeds.rb.
What is the gemfile
The gemfile contains all the gems that your app uses.
With the source on the top that are housed in rubygems.org]
What is bundle install?
Bundle goes to the source and brings the gems that you have in your gemfile and then installs them
How is the gemfile grouped?
group development
group development test
group production
you place the gems depending on which environment you are using
What is the gemfile.lock?
The bundler creates the gemfile.lock adds the dependencies that are needed. Never update this manually.
What is the database.yml?
It says what databased are used and in what environment
What are migrations?
files that we use to create or update databases.
What is a class?
A collection of methods or functionality
What is snake case?
snake_case.rb
All file names should be in snake case
What is a CamelCase
All class names should be CamelCase ApplicationController
What is an action?
An action is a fancy name for a method.
What is a view?
A view is everything you see in your browser.
What does erb stand for?
embedded ruby all html files in rails are called name.html.erb
What is the application.html.erb file?
The application.html.erb file is our wrapper file, that means that all of our view files are a part of that file. All files are displayed through that file.
What is the inside the application.html.erb file?
This is where all your views show up from the other views.
What is the naming convention for the controller files?
Controller file names need to be snake_case