LoginSignup
7
7

More than 5 years have passed since last update.

Rails5.0.0.beta1を触ってみる

Posted at

Rails5.0.0.beta1を導入

ローカルに入っているRailsのバージョンを確認

$ gem search ^rails$ -l

*** LOCAL GEMS ***

rails (4.2.1)

Rails5.0.0.beta1が入っていないので、インストールする

$ gem install rails -v 5.0.0.beta1

Fetching: rack-2.0.0.alpha.gem (100%)
ERROR:  Error installing rails:
    rack requires Ruby version >= 2.2.2.

Rails5はRuby2.2以上が動作環境だと思っていたんですが、2.2.2以上なんですね。。。

ということで、Ruby2.2.2を導入

$ rvm install 2.2.2
$ ruby -v

ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]

再度、Rails5.0.0.beta1をインストール

$ gem install rails -v 5.0.0.beta1

無事、Rails5.0.0.beta1のインストールが完了

$ gem search ^rails$ -l

*** LOCAL GEMS ***

rails (5.0.0.beta1)

Rails5.0.0.beta1のプロジェクトを作成

$ rails new rails5_test
$ cd rails5_test
$ tree
.
├── app
│   ├── assets
│   │   ├── config
│   │   │   └── manifest.js
│   │   ├── images
│   │   ├── javascripts
│   │   │   ├── application.js
│   │   │   ├── cable.coffee
│   │   │   └── channels
│   │   └── stylesheets
│   │       └── application.css
│   ├── channels
│   │   └── application_cable
│   │       ├── channel.rb
│   │       └── connection.rb
│   ├── controllers
│   │   ├── application_controller.rb
│   │   └── concerns
│   ├── helpers
│   │   └── application_helper.rb
│   ├── 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
├── config
│   ├── application.rb
│   ├── boot.rb
│   ├── database.yml
│   ├── environment.rb
│   ├── environments
│   │   ├── development.rb
│   │   ├── production.rb
│   │   └── test.rb
│   ├── initializers
│   │   ├── active_record_belongs_to_required_by_default.rb
│   │   ├── application_controller_renderer.rb
│   │   ├── assets.rb
│   │   ├── backtrace_silencers.rb
│   │   ├── callback_terminator.rb
│   │   ├── cookies_serializer.rb
│   │   ├── cors.rb
│   │   ├── filter_parameter_logging.rb
│   │   ├── inflections.rb
│   │   ├── mime_types.rb
│   │   ├── request_forgery_protection.rb
│   │   ├── session_store.rb
│   │   └── wrap_parameters.rb
│   ├── locales
│   │   └── en.yml
│   ├── redis
│   │   └── cable.yml
│   ├── routes.rb
│   └── secrets.yml
├── config.ru
├── db
│   └── seeds.rb
├── Gemfile
├── Gemfile.lock
├── lib
│   ├── assets
│   └── tasks
├── log
├── public
│   ├── 404.html
│   ├── 422.html
│   ├── 500.html
│   ├── favicon.ico
│   └── robots.txt
├── Rakefile
├── README.md
├── test
│   ├── controllers
│   ├── fixtures
│   │   └── files
│   ├── helpers
│   ├── integration
│   ├── mailers
│   ├── models
│   └── test_helper.rb
├── tmp
│   └── cache
│       └── assets
└── vendor
    └── assets
        ├── javascripts
        └── stylesheets

45 directories, 56 files

プロジェクト作成時のRails4との違い

細かく比較したわけではなく、私がぱっと見た感じなので、間違いがあればご指摘ください。

  • Action CableAction Jobに関するディレクトリやファイルが追加
  • app/models/application_record.rbが追加
  • app/mailers/application_mailer.rbが追加
  • app/assets/configが追加
  • config/initializers/の中身が結構変わってそう

Rails5.0.0.beta1を動かす

Railsサーバを起動

$ bin/rails db:create
$ bin/rails db:migrate
$ bundle exec rails s
=> Booting Puma
=> Rails 5.0.0.beta1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
I, [2015-12-27T07:35:37.723577 #24453]  INFO -- : Celluloid 0.17.2 is running in BACKPORTED mode. [ http://git.io/vJf3J ]
Puma 2.15.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000

bin/rakebin/railsに置き換えて実行できるようになりました。
また、起動されるサーバがWeblickではなくPumaに変わりました。

HomeControllerを作ってみる

$ bin/rails g controller home index
Running via Spring preloader in process 24533
      create  app/controllers/home_controller.rb
       route  get 'home/index'
      invoke  erb
      create    app/views/home
      create    app/views/home/index.html.erb
      invoke  test_unit
      create    test/controllers/home_controller_test.rb
      invoke  helper
      create    app/helpers/home_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/home.coffee
      invoke    css
      create      app/assets/stylesheets/home.css

特に変わったことはなさそうです。

Testモデルを作ってみる

$ bin/rails g model test test:string
Running via Spring preloader in process 24726
      invoke  active_record
      create    db/migrate/20151227082502_create_tests.rb
      create    app/models/test.rb
      invoke    test_unit
      create      test/models/test_test.rb
      create      test/fixtures/tests.yml
class Test < ApplicationRecord
end

ActiveRecord::BaseではなくApplicationRecordを継承するようになっています。

class CreateTests < ActiveRecord::Migration[5.0]
  def change
    create_table :tests do |t|
      t.string :test

      t.timestamps
    end
  end
end

マイグレーションファイルはActiveRecord::Migrationではなく、ActiveRecord::Migration[5.0]を継承するようになってます。[5.0]はなんのためなんでしょうか。。。

Rails5の新機能

Action Cable, API mode, Rails commandなどが目玉としてありますが、それらについては色々なところで紹介されています。
Rails 5.0で追加される主な新機能(Ruby on Rails公式ブログより)
Rails 5 の足音

もう少し色々触ってみる予定でしたが、力尽きたので、今回はこの辺でww

7
7
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
7
7