Rails is...
...a Platform for creating dynamics websites,
using the Ruby programming language.
Rails allows us to utilize Ruby in the Back-End and Front-End
$ rails new my_awesome_project
...
$ cd my_awesome_project
Some Ground Rules:
1. Appropriately Name
* what does the project
do as a whole?
2. Starts with a letter
3. All Lowercase
3. Underscores for Spaces
$ rails g controller Welcome index about contact
g = generate
Welcome = the name of the controller
(but it you can call it whatever you like; capitalized, camelcase)
index about contact = views (or, html pages) that you want associated with this controller (lowercase, with underscores)
When you generate a Controller, Rails provides the routes.
The Root path is your landing (or, home) page.
Call it by it's associated controller action!
# [railsprojectname]/config/routes.rb
Rails.application.routes.draw do
get 'welcome/index'
get 'welcome/about'
get 'welcome/contact'
end
Rails.application.routes.draw do
get 'welcome/index'
get 'welcome/about'
get 'welcome/contact'
root 'welcome#index'
end
No one wants a long URL!
Rails.application.routes.draw do
get 'homepage' => 'welcome#index'
get 'thisisus' => 'welcome#about'
get 'drop_us_a_line' => 'welcome#contact'
root 'welcome#index'
end
Format:
'custom URL extension' => 'controller#action'
$ rails g scaffold Pet name:string breed:string age:integer
Remember when you created an Object 'class' in Ruby?
Doesn't this seem awfully similar to that?!
$ rails g scaffold
The Rails command to create a new database
$ rails g scaffold Pet
'Pet' (notice it's capitalized, and singular), will be the name of our database
$ rails g scaffold Pet name:string
breed:string age:integer
'name', 'breed' and 'age' will be the attributes of your 'Pet'; each is assigned a data type
Think of your Database as a table...
...and your Attributes as the columns.
Each time you create a new instance of the Resource, you create a new row in the table
Rails is a generous framework, and it gives three extra columns, just for stopping by...
You get...
id - an id # of 1 thru ...
created_at - datetime when row was created
updated_at - datetime when the row was updated