Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails6 New Functions

k.yanagimoto
September 25, 2019

Rails6 New Functions

k.yanagimoto

September 25, 2019
Tweet

More Decks by k.yanagimoto

Other Decks in Technology

Transcript

  1. Rails 6
    @kyanagimoto

    View Slide

  2. ॕ Rails 6 release
    • Date: Aug 15th 2019

    • ৽͍͠ίϯϙʔωϯτ Action Text / Action Mailbox

    • Webpackerͷ࠾༻

    • ෳ਺DB઀ଓɺฒྻςετ࣮ߦ(TDD is dead͔ΒͷྲྀΕ)

    • > 2.5

    https://railsguides.jp/6_0_release_notes.html

    View Slide

  3. Action Text
    • WYSIWYG (΢Οδ΢Οά, What You See
    Is What You Getͷུͩͬͯ) EditorͷTrixΛ
    ؆୯ʹ࢖͑ΔΑɻ

    • ActiveStorageΛEditorͰೖྗͨ͠FileΛอ
    ଘ͢Δҝʹར༻͍ͯ͠Δɻ

    WYSIWYG Editor಺ʹFileΛૠೖͨ࣌͠͸
    ActiveStorageʹDirectUpload͞ΕΔ໛
    ༷ɻ

    View Slide

  4. Action Mailbox
    • Mailͷड৴ॲཧͷͨΊͷίϯϙʔωϯτ

    * ActionMailer: MailΛRubyͰ࢖͏ͨΊObjectʹม׵͢ΔͨΊ

    Cloudͷϝʔϧॲཧ΍อଘ͸ࣗલͰ΍Δඞཁ͋ͬͨɻ

    • ActiveStorageʹMailΛอଘɺAction Mailbox༻ͷDB Tableඞཁ

    View Slide

  5. Webpacker
    • Rails಺ͷJavaScript Library͸npmͰެ։͞Ε͍ͯΔ΋ͷΛར༻

    • CoffeeScript…ɻ(Action CableͰGenerate͞ΕΔίʔυ͕มԽ)

    View Slide

  6. ෳ਺DB઀ଓ
    • config/database.yaml
 • app/models/hoge.rb

    • config/environments

    Sample: 

    https://github.com/
    effectiveDevOps/devops_meter/
    blob/master/config/environments/
    production.rb#L109

    View Slide

  7. Parallelize test
    • github.com/rspec/rspec-rails/issues/2104

    rspecͷରԠ͸Ͳ͏΋·ͩΈ͍ͨͳײ͡ɻ

    View Slide

  8. ͱΓ͋͑ͣɺ࡞ͬͯΈ·͠ΐ͏
    $ gem i bundler

    $ gem i rails

    # YarnΛར༻͢ΔͷͰɺInstallɹhttps://yarnpkg.com/en/docs/install

    $ brew install yarn

    $ brew install postgresql

    $ rails new sample -d postgresql

    View Slide

  9. # DockerͰdatabaseཱͯΔ

    $ brew cask install docker

    $ docker run --name dev-postgres -e POSTGRES_USER=nikotama -e
    POSTGRES_PASSWORD=postgres -p 15432:5432 -d postgres:11

    # ֬ೝ

    $ docker container exec -it dev-postgres bash

    $$ psql -U nikotama

    $$ \l #database Ұཡ

    View Slide

  10. $ vi config/database.yml

    ## developmentͷusername, password, host, portΛมߋɻ

    $ rake db:create

    $ bundle exec rails action_text:install

    $ bundle exec rails action_mailbox:install

    $ bundle exec rails db:migrate

    View Slide

  11. # Edit Gemfile

    $ vi Gemfile

    ## image_processingͷίϝϯτΞ΢τΛ֎͢

    $ bundle install

    $ bundle exec rails generate scaffold post title:string body:rich_text

    $ bundle exec rake db:migrate

    View Slide

  12. $ bundle exec rails s

    # Another pane

    $ bin/webpack-dev-server

    # Access to http://localhost:3000/posts

    # WYSIWYG Editorग़ݱɻ

    View Slide

  13. $ docker container exec -it dev-postgres bash

    $$ psql -U nikotama

    $$$ \l

    $$$ \c sample_app_development

    $$$ \d

    $$$ select * from posts;

    $$$ select * from action_text_rich_texts;

    $$$ select * from active_storage_attachments;

    $$$ select * from active_storage_blobs;

    $ tree ./storage/

    View Slide