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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 【第14週】パRails輪読会🚂 \(2023\-11\-20\~ 2023\-11\-24\) ###### 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\-11\-20(月) ### ファシリ @hiromisugie ### ドライバー @ayu-0505 ### 読んだところ 5-5-2 257p から 5-5-4 260p 「Action Textのカスタマイズ」まで。 PR:https://github.com/motohiro-mm/Perfect_Ruby_on_Rails_Ch5/pull/12 ### 次回 5-6 「Action Cableによるリアルタイム通信」から。🚂 ### 学んだこと・感想 - @sharoa - Action Textのエディターで作成されたリッチテキストはActionText ;:RichTextという名前のモデルで管理されている。 - リッチテキストは紐付けられたモデルとは別のテーブルで管理されているため、そこを意識しないとN+1問題に遭遇してしまう。 - Action Textはこの問題を回避ひる専用のeager load用メソッドを用意している。 - with_rich_text_#{name}とwith_rich_text_#{name}_and_embeds - embedsは埋め込むという意味で、 erbはrubyをembedsということらしい。(へ〜ボタンを押したい!!) - eager イーガーと読む。(私もイエガーって呼んでて。進撃の巨人みたいって思ってましたw) - Action TextはバックエンドにTrixを利用している。 - @sadanora - ActionTextのエディタで作成されたリッチテキストは`ActionText::RichText`というモデルで管理されている。 - リッチテキストを扱うモデル(今回はMessage)とActionText::RichTextがポリモーフィック関連で紐付けられる - ので、意識して使わないとN+1を生んでしまうでの注意。 - Action Textにはeager load用のメソッドが用意されているので、それを使うとN+1を回避できる。 - `with_rich_text_#{name}`と`with_rich_text_#{name}_and_embeds` - erbは厳密には`embedded Ruby`らしいです - https://ja.wikipedia.org/wiki/ERuby - @shodan - Action Textのリッチエディターで作成されたテキストは、自分で定義したモデル(今回だと`Message`)とは違うモデルで管理されている。 - ゆえに`Message`モデルからリッチテキストを扱う属性名として使用したカラム名(今回だと`content`)を直接参照すると、内部的には別の紐付けられたテーブルへアクセスするため、N+1問題がおきる可能性がある。 - Action Text専用の`eager_load`用のメソッドが用意されているので、そちらを使用する。 - @motohiro-mm - `bin/rails g scaffold モデル名 属性名:rich_text`とすると、コントローラ、モデル、ビューをActionText用になおしてくれる - リッチテキストは紐づけられたモデルとは別のテーブルに管理されているので、N+1問題が発生する - ActionTextがN+1問題を回避するために、eager load用のメソッドを用意している - `with_rich_text_属性名`:添付ファイルなしで本文をプリロードする - `with_rich_text_属性名_and_embeds`:本文と添付ファイルを両方プリロードする - 自分のN+1問題への理解が薄いので、プラクティス&課題を再度見直そうと思います - @moegi29 - 実際に試して頂いたことでwith_rich_text_#{name}とwith_rich_text_#{name}_end_embedsの違いでembedの場合は埋め込んでいるかリプレゼンテーション?の読み込みがなくて短かった - ActionTextで今まで手動入力してきたことはg scaffold message scontent:rech_textで生成できてしまう! - N+1問題の部分はプラクティスで指摘されたことを思い出しました。 - @ayu-0505 - binディレクトリがgit管理から外れている現象があったので、次回までに解決できるように確認しておきます🙏 - scaffoldで作成時にもrich_textを属性に加えると自動的に反映される。 - N+1問題回避用のメソッド`with_rich_text_#{name}`と`with_rich_text_#{name}_and_embeds`がある。 - Active Storageの`with_attached_attachment_name`が似たようなメソッドだと思った。 - @hiromisugie - Action Textを使ったリッチテキストの入力・表示方法について具体的に流れを確認できた。 - scaffoldで作成した`message`のモデルに`has_rich_text :content`を設定 - フォームに`:content`を設定 - コントローラでストロングパラメータを設定 - ビューに`content`を表示するように追加 - 以上のことはscafflod時点で`content:rich_text`をつけると自動的に設定できる。(できるんかい!と思った) - リッチテキストはポリモーフィック関連を使っており、N+1問題が発生するので、回避用のメソッドを設定する必要がある ------ ## 2023\-11\-21(火) ### ファシリ @moegi ### ドライバー @shodan ### 読んだところ 5-6 「Action Cableによるリアルタイム通信」から 5-6-1 265pの途中まで。 PR:https://github.com/motohiro-mm/Perfect_Ruby_on_Rails_Ch5/pull/13 ### 次回 5-6-1 265p サーバサイドのコードを実装する から。🚂 ### 学んだこと・感想 - @sharoa - Action CacleはWebsocketを使ったリアルタイム処理を提供するライブラリのこと。   - Websocketはクライアント/サーバ間のコネクションを維持し、双方向でデータをやり取りするための通信規格のこと。 - 今日の時点ではまだAction Cableについて詳しく知るための簡単なチャットアプリを作成し始めたところなので、まだよくわかっていない。 - 難しいな〜というのが率直な感想。 - 今後のアプリ完成を待ってみたいと思います。 - @moegi29 - ジェネレーターでActionCable用のファイルを作るところが難しかった。rbはサーバーサイド(コントローラ、view)で呼ばれて、jsはクライアントサイド(ブラウザ)で呼ばれている。それぞれ処理を実行する場所が違う。 - @ayu-0505 - Action CableはWebSocket(HTTPとは違う通信規格)を使用し、リアルタイム通信処理を提供するライブラリ。 - `bin/rails g channel チャネル名? メソッド名?`でAction Cable用のファイル類を作成できる。 - サーバーサイド側のrbファイルがapp/channels/チャネル名_channel.rbで作成され、クライアント側のjsファイルがapp/javascript/channels/チャネル名_channel.jsで作成される。 - 購読はクライアントとチャネルを関連付けすること?? jsファイルは購読用の処理、rbは購読の際の処理っぽい?? - @shodan - Action CableはWebSocketを使ったリアルタイム通信を提供するライブラリ。 - WebSocketはクライアント/サーバ間のコネクションを維持し、双方向でデータをやりとりするための通信企画。 - `rails g channel`でサーバサイド(rubyファイル)とクライアントサイド(JSファイル)の2つのファイルが生成できる。 - クライアントサイドで接続時・切断時・データ受信時に呼び出すコールバックメソッドを用意しておける。 - チャネルが担当することのイメージ(購読って?)が現時点でちょっとイメージできてないのですが、次から動きを見て把握していきたいです。 - 相変わらずモタモタですみません〜。 - @sadanora - WebSocket - 双方向でデータをやりとりするための通信規格 - リアルタイム通信を必要とするアプリなどで利用される - サーバーサイドのコードと、クライアントサイドのコード、という表現がサラッと出てきたけど「何がどこで実行されるのか」を知っていないと何の話をしているのかわからなくなりそうだと思いました。 - クライアントサイド = 処理を実行するのはブラウザ、サーバーサイド = 処理を実行するのはサーバー、という感じが自分の今のところの理解です。 - @hiromisugie - Action CableはWebSocketを使ったリアルタイム処理を提供するライブラリ。WebSocketとは双方向でデータをやり取りするための通信規格…? - roomモデルを作らずにroomコントローラとビューでmessageモデルを入れていく、という構造?がフムフムという感じでした。(もし、ユーザーが自由に複数のチャットルームを立ち上げられる…みたいな構造の場合はroomモデルも必要になるのかな、とか) - `generate channel`のところから難しかった… - サーバサイド用にRubyファイル、クライアントサイド用でJSファイルをそれぞれ使う。それぞれの役割と細かい動きは明日以降具体的に試していける、のかな…! - 独習Railsを読んでいる早朝輪読会仲間のkarlleyさんが来てくれて嬉しかった!😄 - @karlley - `bundle lock` はBundlerのバージョンが上がって自身のplatformが追加されるように仕様が変わった際に`bundle install` できないエラーに対応できる - Railsはjsが絡むとより一層難しくなるという事が良く分かった... - パRailsの書籍も無く雰囲気だけの参加でしたが楽しかったです! 次は書籍を用意して参加します😅 - @motohiro-mm - ActionCable:WebSocketを使ったリアルタイム処理を提供するライブラリ - WebSocket:クライアント/サーバ側のコネクションを維持し、双方向でデータをやり取りするための通信規格 - Webブラウザ↔️JS(クライアント側)↔️WebSocket↔️channel.rb(サーバ側)っていう動き…? - 具体的な動きが今後実装してみられるようになるともっと理解できるのかなと期待しています - 環境構築の`--skip-git`のところはkarlleyさんのブログを参考にさせていただいてます!ありがとうございます! ------

    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