Rails Tutorial 4. Ausgabe: Kapitel 1 Von Null bis Bereitstellung
--Trainieren ―― 1. Auf welcher Website wird das Ruby-Juwel für Ruby on Rails verwendet?
―― 2. Was ist derzeit die neueste Version von Rails?
- v6.0.3.4? https://guides.rubyonrails.org/
―― 3. Wie oft wurde Ruby on Rails bisher heruntergeladen? Bitte probieren Sie es aus.
--247,586,141 Vielleicht können Sie es hier sehen. Ich konnte die neueste Version bestätigen. https://rubygems.org/gems/rails?locale=ja
Kürzung
Das Rails-Tutorial sagte:
Terminal
$ cd #Gehen Sie zu Ihrem Home-Verzeichnis
$ mkdir environment # 'environment'Erstellen Sie ein Verzeichnis
$ cd environment/ # 'environment'Zum Verzeichnis gehen
$ cd ~/environment
$ rails _5.1.6_ new hello_app
Da das Verzeichnis mit dem Namen Umgebung bereits erstellt wurde, habe ich es unter einem anderen Namen erstellt und die Version nicht angegeben, wenn "Rails New".
![]() |
---|
Das Rails-Tutorial schien etwas in der Cloud zu verwenden, aber ich werde mit VS Code codieren. Ich könnte unterwegs zu RubyMine wechseln. Starten Sie VS Code, öffnen Sie die Datei und öffnen Sie hello_app.
![]() |
---|
Wenn Sie das VS-Code-Terminal (TERMINAL) öffnen, sollten Sie sich im Stammverzeichnis Ihrer Anwendung befinden.
![]() |
---|
1.3.1 Bundler
Terminal
-> % bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Using rake 13.0.1
Using concurrent-ruby 1.1.7
Using i18n 1.8.5
・
・
・
Using webpacker 4.3.0
Bundle complete! 17 Gemfile dependencies, 74 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
1.3.2 rails server
Terminal
-> % rails s
=> Booting Puma
=> Rails 6.0.3.4 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.6 (ruby 2.7.1-p83), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
Wenn Sie http: // localhost: 3000 / öffnen, sieht es wie in der folgenden Abbildung aus.
![]() |
---|
--Trainieren ―― 1. Welche Ruby-Version haben Sie jetzt auf Ihrem Computer im Vergleich zu der auf der Standard-Rails-Seite angezeigten Version? Sie können sie leicht anzeigen, indem Sie ruby -v in der Befehlszeile ausführen. Ich werde. - 2.7.1
―― 2. Überprüfen Sie auf die gleiche Weise die Version von Rails. Entspricht die von Ihnen nachgeschlagene Version der in Listing 1.1 installierten Version?
- 6.0.3.4
1.3.3 Model-View-Controller (MVC)
1.3.4 Hello, world!
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def hello
render html: "hello, world!"
end
end
config/routes.rb
Rails.application.routes.draw do
root 'application#hello'
end
![]() |
---|
--Trainieren
―― 1. Schreiben wir die Hallo-Aktion neu, sodass "hola, mundo!" Anstelle von "Hallo, Welt!" Angezeigt wird.
--2 Rails unterstützt auch "Nicht-ASCII-Zeichen". "¡Hola, mundo!" Enthält das auf dem Kopf stehende Ausrufezeichen "¡", das für Spanisch typisch ist (Abb. 1.17) 19. Um das Zeichen "¡" auf Ihrem Mac anzuzeigen, halten Sie die Wahltaste gedrückt und drücken Sie die Taste 1. Es kann schneller sein, dieses Zeichen zu kopieren und in Ihren Editor einzufügen.
--3. Beziehen Sie sich auf die Hallo-Aktion in Listing 1.7 und fügen Sie eine zweite Aktion hinzu, auf Wiedersehen. Diese Aktion zeigt den Text "Auf Wiedersehen, Welt!" An. Bearbeiten Sie das Routing in Listing 1.9, um die Routing-Routing-Zuordnung von der Aktion "Hallo" in die Aktion "Auf Wiedersehen" zu ändern.
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def hello
render html: "hola, mundo!"
end
def goodbye
render html: "goodbye, world!"
end
end
config/routes.rb
Rails.application.routes.draw do
root 'application#goodbye'
end
![]() |
---|
Kürzung
Kürzung
1.4.3 Bitbucket Diesmal habe ich Github benutzt.
Terminal
-> % git init
Reinitialized existing Git repository in /Users/fukadashigeru/environment_2/hello_app/.git/
-> % git add -A
-> % git commit -m "Initialize repository"
[master (root-commit) 02fb3dd] Initialize repository
92 files changed, 9246 insertions(+)
create mode 100644 .browserslistrc
create mode 100644 .gitignore
create mode 100644 .ruby-version
・
・
・
create mode 100644 yarn.lock
-> % git remote add origin https://github.com/**********/hello_app.git
-> % git push origin master
Enumerating objects: 107, done.
Counting objects: 100% (107/107), done.
Delta compression using up to 4 threads
Compressing objects: 100% (89/89), done.
Writing objects: 100% (107/107), 149.16 KiB | 3.47 MiB/s, done.
Total 107 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/**********/hello_app.git
* [new branch] master -> master
Terminal
[~/environment_2/hello_app] [master]
-> % git checkout -b modify-README
Switched to a new branch 'modify-README'
*********************************************
README.Ändern Sie die MD-Datei
*********************************************
[~/environment_2/hello_app] [modify-README]
-> % git commit -a -m "Improve the README file"
[modify-README ba451c3] Improve the README file
1 file changed, 4 insertions(+), 22 deletions(-)
[~/environment_2/hello_app] [modify-README]
-> % git checkout master
Switched to branch 'master'
[~/environment_2/hello_app] [master]
-> % git merge modify-README
Updating 02fb3dd..ba451c3
Fast-forward
README.md | 26 ++++----------------------
1 file changed, 4 insertions(+), 22 deletions(-)
[~/environment_2/hello_app] [master]
-> % git branch -d modify-README
Deleted branch modify-README (was ba451c3).
[~/environment_2/hello_app] [master]
-> % git push origin master
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# development,test,Bewegen Sie hier in Entwicklung und Test, was sich im gesamten Rahmen der Produktion befand
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
#Fügen Sie pg zur Produktion hinzu
group :production do
gem 'pg'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Terminal
-> % heroku login --interactive
› Warning: heroku update available from 7.35.1 to 7.46.0.
heroku: Enter your login credentials
Email [***********@gmail.com]:
Password: ***********
Logged in as ***********@gmail.com
-> % heroku keys:add
› Warning: heroku update available from 7.35.1 to 7.46.0.
Found an SSH public key at /Users/***********/.ssh/id_rsa.pub
? Would you like to upload it to Heroku? Yes
Uploading /Users/***********/.ssh/id_rsa.pub SSH key... done
-> % heroku create
› Warning: heroku update available from 7.35.1 to 7.46.0.
Creating app... done, ⬢ thawing-brook-84469
https://thawing-brook-84469.herokuapp.com/ | https://git.heroku.com/thawing-brook-84469.git
Terminal
-> % git push heroku master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 332 bytes | 332.00 KiB/s, done.
・
・
・
remote: Verifying deploy... done.
To https://git.heroku.com/thawing-brook-84469.git
48ef406..7fc2c4e master -> master
https://thawing-brook-84469.herokuapp.com/
![]() |
---|
Das ist keine Hallo Welt. Vielleicht gab es irgendwo einen Verfahrensfehler. Nun, nein.
--Trainieren
Kürzung
Terminal
-> % bin/rails c
Running via Spring preloader in process 5709
Loading development environment (Rails 6.0.3.4)
irb(main):001:0> ('a'..'z').to_a.shuffle[0..7].join
=> "cntwqkdr"
irb(main):002:0> exit
-> % heroku rename cntwqkdr
Renaming ravudstc to cntwqkdr... done
https://cntwqkdr.herokuapp.com/ | https://git.heroku.com/cntwqkdr.git
Git remote heroku updated
▸ Don't forget to update git remotes for all other local checkouts of the app.
-> % heroku open
![]() |
---|
--Trainieren ―― 1. Führen Sie den Heroku-Hilfebefehl aus, um die Liste der Heroku-Befehle anzuzeigen. Mit welchem Befehl wird das Heroku-App-Protokoll angezeigt?
Terminal
-> % heroku help
CLI to interact with Heroku
VERSION
heroku/7.46.0 darwin-x64 node-v12.16.2
USAGE
$ heroku [COMMAND]
COMMANDS
access manage user access to apps
addons tools and services for developing, extending, and operating your app
apps manage apps on Heroku
auth check 2fa status
authorizations OAuth authorizations
autocomplete display autocomplete installation instructions
buildpacks scripts used to compile apps
certs a topic for the ssl plugin
ci run an application test suite on Heroku
clients OAuth clients on the platform
config environment variables of apps
container Use containers to build and deploy Heroku apps
domains custom domains for apps
drains forward logs to syslog or HTTPS
features add/remove app features
git manage local git repository for app
help display help for heroku
keys add/remove account ssh keys
labs add/remove experimental features
local run Heroku app locally
logs display recent log output
maintenance enable/disable access to app
members manage organization members
notifications display notifications
orgs manage organizations
pg manage postgresql databases
pipelines manage pipelines
plugins list installed plugins
ps Client tools for Heroku Exec
psql open a psql shell to the database
redis manage heroku redis instances
regions list available regions for deployment
releases display the releases for an app
reviewapps manage reviewapps in pipelines
run run a one-off process inside a Heroku dyno
sessions OAuth sessions
spaces manage heroku private spaces
status status of the Heroku platform
teams manage teams
update update the Heroku CLI
webhooks list webhooks on an app
--Trainieren ―― 2. Überprüfen Sie das aktuelle Protokoll der Heroku-App mit dem Befehl in der obigen Übung. Was war das letzte Ereignis? (Wenn Sie sich den Befehl zum Anzeigen dieses Protokolls merken, können Sie Fehler in Ihrer Produktionsumgebung finden.)
Terminal
> % heroku logs
2020-10-19T13:29:19.529499+00:00 app[web.1]: => Run `rails server --help` for more startup options
2020-10-19T13:29:20.730825+00:00 app[web.1]: Puma starting in single mode...
2020-10-19T13:29:20.730870+00:00 app[web.1]: * Version 4.3.6 (ruby 2.7.1-p83), codename: Mysterious Traveller
2020-10-19T13:29:20.730871+00:00 app[web.1]: * Min threads: 5, max threads: 5
2020-10-19T13:29:20.730871+00:00 app[web.1]: * Environment: production
2020-10-19T13:29:20.731100+00:00 app[web.1]: * Listening on tcp://0.0.0.0:41511
2020-10-19T13:29:20.731446+00:00 app[web.1]: Use Ctrl-C to stop
2020-10-19T13:29:21.035771+00:00 heroku[web.1]: State changed from starting to up
・
・
・
Kürzung
Recommended Posts