11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails 5.1.0.beta1 試してみた

Last updated at Posted at 2017-02-25

Rails 5.1.0.beta1 がリリース 🎉

Release v5.1.0.beta1 · rails/rails

Rails 5.1.0.beta1: Loving JavaScript, System Tests, Encrypted Secrets, and more - Riding Rails

主な変更点

Rails 5.1の変更点まとめ - Qiita

実行環境

Rails 5.1.0.beta1
Ruby 2.4.0
node 6.10.0

gem install rails

console
$ gem install rails -v 5.1.0.beta1
ERROR:  While executing gem ... (Gem::DependencyResolutionError)
    conflicting dependencies activesupport (= 3.0.0) and activesupport (= 5.1.0.beta1)
  Activated activesupport-5.1.0.beta1
  which does not match conflicting dependency (= 3.0.0)

  Conflicting dependency chains:
    rails (= 5.1.0.beta1), 5.1.0.beta1 activated, depends on
    activesupport (= 5.1.0.beta1), 5.1.0.beta1 activated

  versus:
    rails (= 5.1.0.beta1), 5.1.0.beta1 activated, depends on
    sprockets-rails (>= 2.0.0), 2.0.0 activated, depends on
    actionpack (>= 3.0), 3.0.0 activated, depends on
    activesupport (= 3.0.0)

Gem::DependencyResolutionErrorが出る👻
下記コマンドでインストール
(cf. Installing pre release gems is giving conflicting dependency errors · Issue #1653 · rubygems/rubygems

console
$ ruby -rbundler/inline -e "gemfile(true) do; source 'https://rubygems.org/'; gem 'rails', '5.1.0.beta1'; end"

$ rails -v
Rails 5.1.0.beta1

ファイル構成

$ rails new rails5-1-0-beta --database=mysql --webpack

上記コマンドで作成したrailsアプリケーションのサンプルは以下

kikunantoka/rails5-1-0-beta1: This is sample app of rails 5.1.0.beta1

rails new で生成される部分はこちら

Execute rails new · kikunantoka/rails5-1-0-beta1@964dbed

package.jsonとyarn.lockが生成されている👍
Gemfileからは gem 'jquery-rails' が消えている

rails s

いつもと変わらない

$ rails db:create
$ rails db:migrate
$ rails s

active_support 5.1.0.beta1がRuby 2.4.0対応したようで、下記warningが出なくなった

/Users/kikunantoka/.anyenv/envs/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/Users/kikunantoka/.anyenv/envs/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated

rails5-1-0-beta1-1.png

encrypted secrets機能を試す

$ rails secrets:setup

rails5-1-0-beta1.png

secrets.yml.encsecrets.yml.key が生成される

secrets.ymlには

# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
# Or, use `bin/rails secrets:setup` to configure encrypted secrets
# and move the `production:` environment over there.

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

と書いてあるので、

$ EDITOR=vim rails secrets:edit

で編集する

1 # See `secrets.yml` for tips on generating suitable keys.
2 # production:
3 #  external_api_key: 1466aac22e6a869134be3d09b9e89232fc2c2289…
4
5 producttion:
6   secret_key_base: generatedsecurerandomhex64

ここに SecureRandom.hex(64) で生成した文字列などを直接書き込む。
Gitで管理されるのは暗号化された secrets.yml.enc なので、ここの文字列は漏れない。
デフォルトのコメントにもあるように、外部サービスのキーなどもここで管理すると良さそう。
CircleCIやProduction環境では、RAILS_MASTER_KEY の環境変数で secrets.yml.key の内容を渡すようだ。

(cf. Rails 5.1 applications can be a lot more secretive on Cloud Foundry and Heroku

終わりに

これからjs周りを試してみる

[2017/02/26] 追記

js周り試してみた

Rails 5.1でreact環境を作ってみた - Qiita

11
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?