sharoa
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 【第11週】パRails輪読会🚂 \(2023\-10\-30\~ 2023\-11\-03\) ###### tags: `パRails🚂` - [開催概要](https://hackmd.io/4A_8ahJtQNi5hz713N5Y7w?view) - [パRails輪読会 ノートまとめ](https://hackmd.io/jsgA8Pf_RVioOgSL_VOR4g) - サンプルコード・正誤表:[サポートページ:パーフェクトRuby on Rails【増補改訂版】:|技術評論社](https://gihyo.jp/book/2020/978-4-297-11462-6/support) - **サンプルコードをダウンロードしただけでは、すぐに`rails s`できない可能性が高い**です。 以下のページに環境構築の手順をまとめたので、ドライバーをやってくださるという方は、こちらに沿って環境構築をお願いします🙏 ⏩ [環境構築の手順 2022年版](https://hackmd.io/y7qb2BRMT2Wd4tAtKYObcQ) ⏩ [環境構築の手順 2023年版](https://hackmd.io/3_lnn8_QRD6wEjwFbWcBzQ) 💁‍♀️ [更新の手順 2章編](https://hackmd.io/pZAmF2EjSmyQ38lUtJ_CqA) ## 目次 [TOC] ------ ## 2023\-10\-30(月) ### ファシリ @moegi29 ### ドライバー @sadanora ### 読んだところ 5-1-4 220p コラムから 5-1-5 終わりまで。 PR: ### 次回 5-1-6 223p 「ジョブの例外処理」から。🚂 ### 学んだこと・感想 - @sharoa - 今日も今日とて難しい。。 - もはや感想しか言えない。 - Active-jobではバックエンドにある複数のキューを扱うことができる。 - 非同期実行したい処理ごとにキューを分けておくことでバックエンドキュー上でのジョブの把握が容易になるらしい。 - ジョブクラスごとに追加するキューを指定するには`queue_as` メソッドを使うらしい。 - Railsの機能の中にはActive Jobを利用している機能が多数ある。その中のAction Mailerのdeliver_laterメソッドはActive job経由でメール送信を非同期実行する。 - @moegi29 - Active~という名前が多くてActiveJobは非同期タスクを実行するライブラリということを忘れがち。。 - バックエンドにSidekiqを使うときActibJobを利用してSidekiqを使う方法とSidekiqのAPIを直接使う方法がある。 - ジョブクラスごとにキューをわけておくことでジョブの把握が容易になる。ジョブクラスごとに追加するキューを指定するにはqueue_asメソッドを使う - Marshalはシリアライズ、デシリアライズの処理を行うもの - async エィシンクと読む - @motohiro-mm - アダプターはデフォルトでasyncだが、他にもSidekiqとかがある - アダプターはSidekiqでActiveJobを使う方法と、SidekiqのAPIを直接使う方法がある - 複数のキューを管理したいときは`queue_as`メソッドに設定。処理ごとに分けると把握しやすい。 - やりたいのにやれない悲しい。テキスト通りにすすめててもなかなか難しい。 - @sadanora - Active Jobではバックエンドにある複数のキューを扱うことができる。 - ジョブごとに追加するキューを指定するには`queue_as`メソッドを使う。 - docker急に出てきて身動き取れない気持ち。 - 読んでいてもピンとこない話が割と長いこと続いている気がするので振り返りとかやってもいいのかも? - @ayu-0505 - Active Jobと非同期バックエンドの直接利用は状況において変更する。 - キューはデフォルトでは1つ?だがキュー管理として複数のキューを追加し、ジョブを振り分けることができる。 - 最近見たネットの記事で、キューは下から取り出すタオル棚のイメージがあって、なるほど〜となってました。 ------ ## 2023\-10\-31(火) ### ファシリ @sharoa ### ドライバー @moegi29 ### 読んだところ 5-1-6 223p 「ジョブの例外処理」から 5-2-1 227p 終わりまで。 PR: https://github.com/motohiro-mm/Perfect_Ruby_on_Rails_Ch5/pull/3 ### 次回 5-2-2 227p 「Active Storageの動作と設定」から。🚂 ### 学んだこと・感想 - @sharoa - Active jobにはジョブをリトライするためのretry_onとジョブを破棄するためのdiscard_onという例外処理がある。 - Sidekiqなどバックエンド側でリトライの仕組みをもっているものがあり、retry_onの注意として二重でリトライが走らないようにする必要がある。 - Active storageの画像アップロード機能が目の前で確認できてよかった。 - @moegi29 - ActiveJobではジョブを実行したときに発生した例外をキャッチして対応を変える仕組みがある。retry_onとdiscard_onを使って例外処理をする。 - retry_onではいろんなオプションが指定できる。Sidekiqでもバックエンド側でリトライの仕組みをもっていることがあるので注意。 - Rails5.2からファイルアップロード機能としてActiveStorageが提供されるようになった。 - 今日はエラーがでずよかった - @sadanora - ジョブの例外処理 - Active Jobは例外をキャッチする仕組みを持っている - `retry_on` - ジョブをリトライする - Sidekiqなどでもリトライの仕組みを持っていたりするので、被らないように注意 - `discard_on` - ジョブの破棄 - 例外処理のテスト - `ActiveJob::TestCase`を継承したクラスで実装する - ActiveStorage - 画像アップロードを簡単に実装できる - attachmentで、ActiveStorage用属性を指定できる ------ ## 2023\-11\-01(水) ### ファシリ @ayu-0505 ### ドライバー @motohiro-mm ### 読んだところ 5-2-2 227p 「Active Storageの動作と設定」から 5-2-5 「ダイレクトアップロード機能」まで。 PR:https://github.com/motohiro-mm/Perfect_Ruby_on_Rails_Ch5/pull/4 ### 次回 5-2-6 233p 「Active Storageの問題点」から。🚂 ### 学んだこと・感想 - @ayu-0505 - Active Stroage機能は2つのモデル(Blob,Atttachment)で構成される。画像の取り扱い機能。 - 本番環境のクラウドストレージサービスも学習が必要かも。 - ダイレクトアップロードはメリットデメリットについてもう少し調べていきたい。 - @sadanora - 途中参加で中身全然はいってこなかったw - Active Storageはポリモーフィック関連付けによって画像を紐づけるモデルと画像を紐づけている - `ActiveStorage::Attachment`は`ActiveStorage::Blob`との中間テーブル - `ActiveStorage::Blob`は画像のメタ情報を格納している - @sharoa - 今日は比較的わかりやすくて、ふむふむと思えた。(それでもなんだこれ、みたいな単語?もあるけど。) - 他のアップロード用のgemと同様にActive Storageにもサムネイル生成の機能がついている。 - ただ、画像アップロード用のgemによってサムネイル生成のタイミングが異なる。   - CarrierWaveはアップロードしたタイミングでサムネイルを生成   - Shrineはアップロードした後に非同期でサムネイルを生成可能   - Active Storageはサムネイル画像用のURLにアクセスしたタイミングでサムネイルを生成 - ファイルへのアクセス制限で、Active Storageを利用した場合、ユーザーの目に触れるURLは必ずアプリケーションサーバのドメインになる。アプリケーションサーバにリクエストが届くとサーバはファイル用の期限付きURLを作成し、そこにリダイレクトする。(期限はデフォルトで5分) - @hiromisugie - Active Storageについて、プラクティスでやったところを復習することができて良かった。 - Active Storageはポリモーフィック関連を採用している。 - 画像のアップは、実際のアプリではS3、GCS、Azureなどにアップするので、この3つはデフォルトで選択できるようになっている。 - サムネイル作成はImageMagickを使う。これもプラクティスでやったがほぼ忘れていたので改めて読めて良かった…! - Active Storageは、ファイルへのアクセス制限を現実的な形で実現できる。(ページにアクセス制限をかけつつ、画像そのものは期限付きURLへリダイレクトすることで、公開されても被害を抑えることができる) - ダイレクトアップロード機能は、アプリケーションサーバを経由せずにファイルを直接クラウドストレージにアップできる。これによりアップロードにかかる時間を減らし、アプリケーションサーバへの負荷を軽減できる。 - 良いことづくめな気がするが、「ダイレクトアップロードでは、ファイルがアップロードされたにもかかわらずレコードにまったくアタッチされないことがある」らしい(Railsガイドより)。理解が及んでいないけど、注意事項もあるということも一旦わかりました。 - @motohiro-mm - Active Storageの機能は2つのモデルで作られる -  ActiveStorage::Attachment→主となるモデルとBlobとの中間テーブルに相当するモデル -  ActiveStorage::Blob→アップロードファイルのメタ情報を管理するモデル -  `has_one_attached :portrait`:userとblobを1対1で紐づける -  サムネイル作成はImageMagickとImageProcessingを使う -  ファイルへのアクセス制限は期限付きURLを生成することで被害を限定的に抑える -  ダイレクトアップロード機能 -  アプリケーションサーバを経由しないことで、アップロードにかかる時間を減らせる -  ファイルがアップロードしたのにレコードにアタッチされない可能性がある -  blobがなんなのか分かりました - @moegi29 - ActiveStorageの機能はActiveStorage::AttachmentとActiveStorage::Blobの2つでできている - ActiveStotageはデフォルトでS3,GCS,AzureStorageの3つのクラウドストレージに対応していて、GCSはGoogleクラウドストレージのことだった。 - ActiveStorageがファイルへのアクセス制限をしてくれる機能は便利そう。 -----

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully