いまや、新人プログラマの最初の難関として知られるようになったRailsチュートリアルをやってみることにする。
Railsが無かった頃からのRubyユーザーで、なんだかんだと日常の道具としてRubyを使って20年だが、 Railsは仕事が暇な時期にちょびっと本を読んでちょっとだけ触ってみたことしかない。それも、もう10年以上前の話だ。
Railsチュートリアルに書いてあることもやったことないのにRubyistを名乗るのもおこがましいし、 プロトタイピングの機会はいろいろとあるので、ちゃんとやってみようと思う。
しかし、Rubyでちゃんとアプリを作ったことがないから、Rubygemsはまだしも、 bundlerをちゃんと理解してない。後の世に大きな影響を与えたプロダクトなんだからとても良くないなあ。
さて、心新たに第1章から読んで行ってみることにする。
1.2で環境セットアップをしているが、いきなりクラウドIDE(Cloud9)を使えと言ってくる。 時代を感じるなあ・・・。とりあえず、ローカルにセットアップしてみよう。
Ruby初学者のRuby On Rails 環境構築【Mac】 - Qiita
に従って導入する。rbenvまでは入れてあるので、bundlerの導入から。
> gem install bundler Fetching: bundler-1.17.1.gem (100%) Successfully installed bundler-1.17.1 Parsing documentation for bundler-1.17.1 Installing ri documentation for bundler-1.17.1 Done installing documentation for bundler after 4 seconds 1 gem installed
> brew install mysql ==> Installing dependencies for mysql: openssl ==> Installing mysql dependency: openssl ==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2p.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring openssl-1.0.2p.high_sierra.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the SystemRoots keychain. To add additional certificates (e.g. the certificates added in the System keychain), place .pem files in /usr/local/etc/openssl/certs and run /usr/local/opt/openssl/bin/c_rehash openssl is keg-only, which means it was not symlinked into /usr/local, because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries. If you need to have openssl first in your PATH run: echo 'set -g fish_user_paths "/usr/local/opt/openssl/bin" $fish_user_paths' >> ~/.config/fish/config.fish For compilers to find openssl you may need to set: set -gx LDFLAGS "-L/usr/local/opt/openssl/lib" set -gx CPPFLAGS "-I/usr/local/opt/openssl/include" For pkg-config to find openssl you may need to set: set -gx PKG_CONFIG_PATH "/usr/local/opt/openssl/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/openssl/1.0.2p: 1,793 files, 12.3MB ==> Installing mysql ==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.12.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring mysql-8.0.12.high_sierra.bottle.tar.gz ==> /usr/local/Cellar/mysql/8.0.12/bin/mysqld --initialize-insecure --user=tambara --basedir=/usr/lo ==> Caveats We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation MySQL is configured to only allow connections from localhost by default To connect run: mysql -uroot To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start ==> Summary 🍺 /usr/local/Cellar/mysql/8.0.12: 255 files, 233.0MB ==> Caveats ==> openssl A CA file has been bootstrapped using certificates from the SystemRoots keychain. To add additional certificates (e.g. the certificates added in the System keychain), place .pem files in /usr/local/etc/openssl/certs and run /usr/local/opt/openssl/bin/c_rehash openssl is keg-only, which means it was not symlinked into /usr/local, because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries. If you need to have openssl first in your PATH run: echo 'set -g fish_user_paths "/usr/local/opt/openssl/bin" $fish_user_paths' >> ~/.config/fish/config.fish For compilers to find openssl you may need to set: set -gx LDFLAGS "-L/usr/local/opt/openssl/lib" set -gx CPPFLAGS "-I/usr/local/opt/openssl/include" For pkg-config to find openssl you may need to set: set -gx PKG_CONFIG_PATH "/usr/local/opt/openssl/lib/pkgconfig" ==> mysql We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation MySQL is configured to only allow connections from localhost by default To connect run: mysql -uroot To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start > mysql.server start Starting MySQL . SUCCESS!
Rubyのバージョンを固定しておく。
> cd study/ > mkdir rails_study > cd rails_study/ > rbenv local 2.5.1 > ls -a . .. .ruby-version
Railsのインストール
> bundle init Writing new Gemfile to /Users/tambara/study/rails_study/Gemfile > vi Gemfile ### <== gem "rails"の行のコメントアウトを外す > cat Gemfile # frozen_string_literal: true source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } gem "rails" > bundle install --path=vender/bundle Fetching gem metadata from https://rubygems.org/.......... Fetching gem metadata from https://rubygems.org/. Resolving dependencies... Fetching rake 12.3.1 Installing rake 12.3.1 Fetching concurrent-ruby 1.1.3 Installing concurrent-ruby 1.1.3 Fetching i18n 1.1.1 Installing i18n 1.1.1 Fetching minitest 5.11.3 Installing minitest 5.11.3 Fetching thread_safe 0.3.6 Installing thread_safe 0.3.6 Fetching tzinfo 1.2.5 Installing tzinfo 1.2.5 Fetching activesupport 5.2.1 Installing activesupport 5.2.1 Fetching builder 3.2.3 Installing builder 3.2.3 Fetching erubi 1.7.1 Installing erubi 1.7.1 Fetching mini_portile2 2.3.0 Installing mini_portile2 2.3.0 Fetching nokogiri 1.8.5 Installing nokogiri 1.8.5 with native extensions Fetching rails-dom-testing 2.0.3 Installing rails-dom-testing 2.0.3 Fetching crass 1.0.4 Installing crass 1.0.4 Fetching loofah 2.2.3 Installing loofah 2.2.3 Fetching rails-html-sanitizer 1.0.4 Installing rails-html-sanitizer 1.0.4 Fetching actionview 5.2.1 Installing actionview 5.2.1 Fetching rack 2.0.6 Installing rack 2.0.6 Fetching rack-test 1.1.0 Installing rack-test 1.1.0 Fetching actionpack 5.2.1 Installing actionpack 5.2.1 Fetching nio4r 2.3.1 Installing nio4r 2.3.1 with native extensions Fetching websocket-extensions 0.1.3 Installing websocket-extensions 0.1.3 Fetching websocket-driver 0.7.0 Installing websocket-driver 0.7.0 with native extensions Fetching actioncable 5.2.1 Installing actioncable 5.2.1 Fetching globalid 0.4.1 Installing globalid 0.4.1 Fetching activejob 5.2.1 Installing activejob 5.2.1 Fetching mini_mime 1.0.1 Installing mini_mime 1.0.1 Fetching mail 2.7.1 Installing mail 2.7.1 Fetching actionmailer 5.2.1 Installing actionmailer 5.2.1 Fetching activemodel 5.2.1 Installing activemodel 5.2.1 Fetching arel 9.0.0 Installing arel 9.0.0 Fetching activerecord 5.2.1 Installing activerecord 5.2.1 Fetching mimemagic 0.3.2 Installing mimemagic 0.3.2 Fetching marcel 0.3.3 Installing marcel 0.3.3 Fetching activestorage 5.2.1 Installing activestorage 5.2.1 Using bundler 1.17.1 Fetching method_source 0.9.2 Installing method_source 0.9.2 Fetching thor 0.20.3 Installing thor 0.20.3 Fetching railties 5.2.1 Installing railties 5.2.1 Fetching sprockets 3.7.2 Installing sprockets 3.7.2 Fetching sprockets-rails 3.2.1 Installing sprockets-rails 3.2.1 Fetching rails 5.2.1 Installing rails 5.2.1 Bundle complete! 1 Gemfile dependency, 41 gems now installed. Bundled gems are installed into `./vender/bundle` > bundle exec rails -v Rails 5.2.1