RUBY ON RAILS - CRUD
Links
// CREATE A CRUD DATABASE
Create Schema / Migration
rails g scaffold friends first_name:string last_name:string email:string phone:string twitter:string
-> This creates a model, a database table called "friends" with the columns and the types
It creates many things: migration, routes,
in db folder there is a migrate folder with the data of the table
PUSH the migration live
rails db:migrate
-> Creates a schema file in migrate folder
Now in views there's a friends directory
it will create a scaffolds.scss that could conflict with Bootstrap, then delete
This creates a fully functioning CRUD automatically that works. Creates the pages, methods, database
in routes (config) it will add automatically resources :friends
In the video example, it creates new links in the navBar to add friends, edit friends, read friends
// STYLE APP WITH BOOTSTRAP <
Tables, buttons
Alerts when user has been CREATED
_Alerts.html.erb copy the alert code
<%= notice %>
<%= if notice %>
<%= render 'layouts/alerts' %>
<%= end %>
// GEM FILES <
Ruby Gems we will use Devise
Add to the Gemfile file: gem 'devise', '~> 4.8'
Go to terminal> bundle install
rails generate devise:install -> It would inform of things we have to add/change
go to congif > environments development.rb and production.rb (when uploading web to heroku)
add rails g devise:views
rails generate devise USER - generate a user's table with name user (name can be changed)
Push the migration:
rails db:migrate
LOGIN SIGN UP SIGN IN SIGN OUT
<%= if user_signed_in? %>
//STYLE DEVISE VIEWS <
Log in log out etc
carpeta views > devise
// <