Rubyの2.6とRails6のbetaが出たのでrails newした。

トゥース。すろっくさんだよ。

あーつかれた今年も終わりかーと思ったら二月ですよ。Ruby2.6は例年通り12月に、Rails6はbeta版が、4月のRubyKaigiのあたりで正式版がでるそうですね。

なのでRails6の予習として、beta版でアプリ作ってみることにしました。

musiclinksはお亡くなりになられたのでアプリケーションの名前は「コミラフ」とでもして漫画のネーム投稿サイトとかにしてみますか。やることは認証・投稿・画像アップロード・一覧表示・ユーザページ・見る専ページってとこですかね。

Ruby2.6.1をrbenvでもrvmでも入れときます。

bundlerはRuby2.6から標準で組み込まれているので、gem install bundlerは不要です。


$ mkdir comirough
$ cd comirough
$ bundle init

次はRubyのバージョンと、gemset。


$ echo 2.6.1 > .ruby-version
$ echo comirough > .ruby-gemset
$ cd .

アプリケーション直下にGemfileというファイルがあるので開いて、以下を書く。


frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'rails', '~> 6.0.0.beta1'

いれます。


$  bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.3.2
Fetching concurrent-ruby 1.1.4
Installing concurrent-ruby 1.1.4
Fetching i18n 1.5.3
Installing i18n 1.5.3
Using 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 6.0.0.beta1 
Installing activesupport 6.0.0.beta1
・・・・・・
・・・・・
% rails -v
Rails 6.0.0.beta1 <---6〜

プロジェクト開始。6でもこれでいいらしい。途中でactiontextとかでるとワクワクしちゃうね。


$ rails new . -d mysql

・・・・
・・・・
Using activestorage 6.0.0.beta1
Using mini_mime 1.0.1
Using mail 2.7.1
Using actionmailbox 6.0.0.beta1
Using actionmailer 6.0.0.beta1
Using actiontext 6.0.0.beta1
・・・・
・・・

ちなみに今回からフロントエンド、webpackが用意されるようになりました。yarnで入るのでyarnをインストールしておく必要があるようです。これはあとで。


Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.

Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.

For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0

Post-install message from sass:

Ruby Sass is deprecated and will be unmaintained as of 26 March 2019.

* If you use Sass as a command-line tool, we recommend using Dart Sass, the new
  primary implementation: https://sass-lang.com/install

* If you use Sass as a plug-in for a Ruby web framework, we recommend using the
  sassc gem: https://github.com/sass/sassc-ruby#readme

* For more details, please refer to the Sass blog:
  http://sass.logdown.com/posts/7081811

こんなファイル&ディレクトリがフォルダの下に作成される。この辺はRails5と代わり映えないかも。bin/の下にyarnができましたね。フロントエンド扱うときはyarnを使いなさい。って。


/
├── .ruby-version
├── .ruby-gemset
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
│   ├── assets
│   │   ├── config
│   │   │   └── manifest.js
│   │   ├── images
│   │   └── stylesheets
│   │       └── application.css
│   ├── channels
│   │   └── application_cable
│   │       ├── channel.rb
│   │       └── connection.rb
│   ├── controllers
│   │   ├── application_controller.rb
│   │   └── concerns
│   ├── helpers
│   │   └── application_helper.rb
│   ├── javascript
│   │   ├── channels
│   │   │   ├── consumer.js
│   │   │   └── index.js
│   │   └── packs
│   │       └── application.js
│   ├── jobs
│   │   └── application_job.rb
│   ├── mailers
│   │   └── application_mailer.rb
│   ├── models
│   │   ├── application_record.rb
│   │   └── concerns
│   └── views
│       └── layouts
│           ├── application.html.erb
│           ├── mailer.html.erb
│           └── mailer.text.erb
├── bin
│   ├── bundle
│   ├── rails
│   ├── rake
│   ├── setup
│   ├── spring
│   ├── update
│   └── yarn
├── config
│   ├── application.rb
│   ├── boot.rb
│   ├── cable.yml
│   ├── credentials.yml.enc
│   ├── database.yml
│   ├── environment.rb
│   ├── environments
│   │   ├── development.rb
│   │   ├── production.rb
│   │   └── test.rb
│   ├── initializers
│   │   ├── application_controller_renderer.rb
│   │   ├── assets.rb
│   │   ├── backtrace_silencers.rb
│   │   ├── content_security_policy.rb
│   │   ├── cookies_serializer.rb
│   │   ├── filter_parameter_logging.rb
│   │   ├── inflections.rb
│   │   ├── mime_types.rb
│   │   └── wrap_parameters.rb
│   ├── locales
│   │   └── en.yml
│   ├── master.key
│   ├── puma.rb
│   ├── routes.rb
│   ├── spring.rb
│   └── storage.yml
├── config.ru
├── db
│   └── seeds.rb
├── lib
│   ├── assets
│   └── tasks
├── log
├── package.json
├── public
│   ├── 404.html
│   ├── 422.html
│   ├── 500.html
│   ├── apple-touch-icon-precomposed.png
│   ├── apple-touch-icon.png
│   ├── favicon.ico
│   └── robots.txt
├── storage
├── test
│   ├── application_system_test_case.rb
│   ├── channels
│   │   └── application_cable
│   │       └── connection_test.rb
│   ├── controllers
│   ├── fixtures
│   │   └── files
│   ├── helpers
│   ├── integration
│   ├── mailers
│   ├── models
│   ├── system
│   └── test_helper.rb
├── tmp
│   └── storage
└── vendor

サーバ起動しますかねーっていったらこんな風に怒られるので注意


% rails server -p 3000                                                                                                                                                                           (git)-[master] ?
=> Booting Puma
=> Rails 6.0.0.beta1 application starting in development
=> Run `rails server --help` for more startup options
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment

config/webpacker.ymlがない。本来ならここでrails webpacker:installとかすればいいんだけど、binの中のyarnが認識してくれない。


% brew install yarn

そして作る。


% rails webpacker:install                                                                                                                                                                        
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
      create  config/webpacker.yml
Copying webpack core config
      create  config/webpack
      create  config/webpack/development.js
      create  config/webpack/environment.js
      create  config/webpack/production.js
      create  config/webpack/test.js
Copying postcss.config.js to app root directory
      create  postcss.config.js
Copying babel.config.js to app root directory
      create  babel.config.js
Copying .browserslistrc to app root directory
      create  .browserslistrc
The JavaScript app source directory already exists
       apply  /Users/ayase-underdog/.rvm/gems/ruby-2.6.1@comirough/gems/webpacker-4.0.0.rc.7/lib/install/binstubs.rb
  Copying binstubs
       exist    bin
      create    bin/webpack
      create    bin/webpack-dev-server
      append  .gitignore
・・・・
・・・・
・・・・

あらためて


% rails server -p 3000
=> Booting Puma
=> Rails 6.0.0.beta1 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.0 (ruby 2.6.1-p33), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

表示されましたね。

僕らの戦いは始まったばかりです。これから作るところは時を見て書いていきます。