** Windows 10 environment construction ** In practice, HyperV Manager already has a virtual environment. ** Install Ubuntu 18.04.3 ** ** rbenv 1.1.2-30-gc879cb0 ** Install from GitHub using Git. ** Ruby 2.5.1 ** Install ** Rails ** installation ** Node.js ** installation
When using JavaScript, it has a function to compress JavaScript for efficient delivery, but it is installed because it requires a JavaScript runtime.
** Install and set up PostgreSQL **
Start PostgreSQL.
sudo service postgresql start
sudo su postgres -c'createuser -s {Ubuntu login user}'
When I hit, I got the following error.
psql: FATAL: role “postgres” does not exist
I entered the Ubuntu login user name without {} and it passed smoothly.
Use scaffold to automatically generate a "user management application" with the name scaffold_app with Rails commands.
rails new scaffold_app -d postgresql
The rails new
command creates a Rails application template.
Specify the name of the application as scaffold_app
.
The scaffold_app directory and related files are generated and logged.
After this, bundle install will be executed automatically and the gem required to run Rails will be installed.
Creating a database. Based on the definition in the file config / databese.yml.
bin/rails s db:create
Instead of "rails", "bin / rails" calls a script called rails in the bin directory directly under the application root directory. You can execute rails command in the environment where gem can be used according to Gemfile.
** Rails server start **
bin/rails s
rails uses Puma as the standard HTTP server.
** Check the server startup with a web browser ** Enter http: // localhost: 3000 / in the address bar.
** Create a template for user management functions **
Automatically generate scaffolds for "users".
bin/rails generate scaffold user name:string address:string age:integer
** Create a table for user management function in the database. ** **
bin/rails db:migrate
** Display user list screen **
http://localhost:3000/users
Access the WEB browser by entering the above URL.
** Points I thought were important **
--The function "CRUD" required to manage users has been generated. ** "create" "read" "update" "delete" ** --Code path Rails application is composed of ** MVC (Model View Controller) **. The controller is called. The controller defines a method called "action" that describes the processing for the request (idnex action when the list screen is accessed).
Recommended Posts