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
    # 【第9週】パRails輪読会🚂 \(2023\-10\-16\~ 2023\-10\-20\) ###### 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\-16(月) ### ファシリ @motohiro-mm ### ドライバー @hiromisugie ### 読んだところ 4-2-2 192p 「本番環境向けのビルド」から 4-3-1 199p 終わりまで。 PR: ### 次回 4-3-1 200p 「手軽にAjax通信を行う」から。🚂 ### 学んだこと・感想 - @sharoa - プリコンパイルの項目、難しかったので、後でまた読み返したいと思います。 - railsには画面の制御を補助するJavascriptライブラリrails-ujsが組み込まれている。 - submitボタンの押下時にダイアログを表示したり、入力フォームの内容を二重送信しないように制御できたりする、 - 直接Javascriptを書かなくてもビューテンプレートに少し記述するだけで実現できる。 - 二重送信を防ぐ機能と、ダイアログを表示させる機能を、画面で確認できたのは良かった! - @motohiro-mm - 本番環境ではあらかじめビルド済みのCSSファイルを配信するために、プリコンパイルをする`bin/rails assets:precompile` - `RAILS_ENV=production bin/rails assets:precompile`するとファイル内のプログラムが縮小化されより軽量なファイルが生成される - プリコンパイルしたファイルを読み取るには`RAILS_SERVE_STATIC_FILES=1 RAILS_ENV=production bin/rails s` - CSSファイルに`.debug`がつかなくなる - rails-ujsの動きが見て分かりやすくて勉強になりました - Rails7からはrails-ujsは非推奨でデフォルトにturboが使われていた気がします - @moegi29 - publicディレクトリ以下をRails自身で配信するかどうかは`config/environments/production.rb`内の設定にある環境変数の有無で切り替えられる。実際に環境変数を書いて実行したことでCSSが適用されたのが確認できた。 - rails-ujsを使うとJSを書かなくてもビューテンプレートに追記することで実行できるのは便利。 - sugieさんの環境はビルドもrails newも速くていいなぁと思いました。 - @sadanora - Kindleが全然本開けなくて対処してるうちに輪読会おわってしまったw - 最終的にAmazonの公式からじゃなくてAppStoreからアプリをダウンロードしたらちゃんと動いているっぽい - ちょっと前の情報だと「mac OS版はAppStoreじゃなくてAmazonからダウンロードせい」みたいなのもみかけた気がするけど、いまはAmazonの方のが安定してないのかなあ... - 全然輪読会と関係ない話でした📕 - @hiromisugie - 本番環境ではあらかじめビルド済みのCSSを配信することで待ち時間を発生させないようにする。これをプリコンパイルという? - ビルド済みのJSやCSSの静的ファイルはRailsが配信するのではなくnginxなどのサーバを通じて配信する、らしい。ふむふむ…?「本番環境でちゃんと表示するか確認する」みたいな場合にはまだまだ知らなければいけないことが沢山ありそう。 - rails-ujsによる画面制御について、画面で確認しながら進められて良かった。仕組みの理解は足りてないと思うけど、「ここをこう変えるとこう動作する」と見えるのは良い…! - `rails new`の時に気をつけることを、毎回忘れる。。。 - webpackerのバージョンアップ等 - gitが二重にならないように`rails new アプリ名 --skip-git`というオプションをつける。(←これはこれで、master.keyなどの重要な情報がgitに上がるというマズイ状態を対処する必要あり。)skipを忘れた場合は、後で`.git`のフォルダを消せば大丈夫そう。(master.keyとかはグレーになっていることを確認済み) ------ ## 2023\-10\-17(火) ### ファシリ @sharoa ### ドライバー @motohiro-mm ### 読んだところ 4-3-1 200p 「手軽にAjax通信を行う」から 4-4-2 205p 「RailsプロジェクトにStimulusを追加する方法」まで。 PR:https://github.com/motohiro-mm/Perfect_Ruby_on_Rails_Ch4/pull/8 ### 次回 4-4-3 205p 「Stimulusの機能概要」から。🚂 ### 学んだこと・感想 - @sharoa - 全体的な感想として、Javascriptめっちゃ出てくるやん!です。 - JSのこと、ある程度知ってる上での内容が今後もたくさん出てくるんだろうな、と思うと少しゾッとしますが、頑張ってついていきたいです。 - Ajaxによる通信を行うと、表示しているページの操作が可能なまま非同期でのサーバとデータのやり取りを行うことができて、必要な部分のみ画面遷移を行えて軽量な画面遷移を実現することができるとのこと。 - ヘルパーメソッドの`form_with`はデフォルトでAjax通信を行う設定になっていて、`local:true`と明示することで通常の画面遷移になる。 - Scaffoldで生成した`form`は明示的に`local:true`と指定されているため、Ajaxではなく通常の画面遷移を行うようにしている。 - @moegi29 - rails-ujsにはHTTPリクエストをAjax化するための機能もついている。実際にform_withの記述を変更してレスポンスデータを確認することでAjax化通信されていることがわかりました。 - TurbolinksはAjaxリクエストで取得したHTMLデータのbodyタグ内を現在表示しているbodyタグへ反映させることで高速なページ遷移を実現するライブラリ。 - window.fooはJSのコードで'window'オブジェクトはブラウザのグローバルオブジェクトでブラウザ全体で共有される変数や関数を格納するためのもの。 - @shodan - `form_with`はデフォルトではAjax通信を行う設定になっており、`local: true`と設定することで通常の画面遷移にできる。 - そのAjax通信の仕組みをRailsで高速に実現しているのが`Turbolinks`というライブラリで、Rails7では`Turbo`。 - Turbolinksは通常のJSとは異なる独自のイベントを用意している。`Turbolinks:load`イベントはTurbolinksもよって画面遷移が行われたときに発火する。 - JS入門しましたがすでに苦手意識が。。なんとか乗り越えていきたい……。 - @motohiro-mm - TurbolinksはAjax通信で高速なページ遷移を実現する - rails-ujsでもAjax通信での画面遷移ができる(`local:false`にする) - イベントリスナーにイベントを追加すると、そのイベントごとにブラウザのコンソールにメッセージが表示される(発火というらしい) - 今回はTurbolinksによって画面が切り替わったときに発火したらしい - 速いTurbolinksを使うにあたり可読性が下がらないようにする規約としてStimulusというフレームワークがある - Stimulusの細かいことは明日学びたいです - @ayu-0505 - Ajax通信という非同期でサーバーとやり取りを行うことにより、高速な通信を可能とする技術がある。それはform_withにおいてlocal: falseに明示的に変更すると利用できる。(普通はtrue) - Turbolinks(現Turbo)では、headの情報更新をせず、bodyタグ内をやり取りすることで高速通信を行う。 - JSの知識が必要なので、このあたりはより学習が深まってからの復習が必要。 - JSフレームワークにも種類があるが、Stimulusはサーバーサイド寄りの控えめなフレームワーク。Turbolinksにおける規約がないことによる可読性不足を補うためのもの。 - @sadanora - TurbolinksはAjax通信によって高速なページ遷移を実現する - Rails7ではTurbolinksはTurboに名前が変わって、rails-ujsが持ってた機能も引き受けてたはず。 - [猫でもわかるHotwire入門](https://zenn.dev/shita1112/books/cat-hotwire-turbo/viewer/tips#:~:text=%E3%81%93%E3%82%8C%E3%82%89%E3%81%AE%E6%A9%9F%E8%83%BD%E3%81%AFTurbo%E3%81%8C%E5%85%A8%E3%81%A6%E5%90%B8%E5%8F%8E%E3%81%99%E3%82%8B%E5%BD%A2%E3%81%AB%E3%81%AA%E3%81%A3%E3%81%9F%E3%82%88%E3%80%82) - Hotwireで自作サービス作ってるくせに、Ajaxが何か説明しようと思うとできないので勉強したいと思いました。 - [AJAX \- 開発者ガイド \| MDN](https://developer.mozilla.org/ja/docs/Web/Guide/AJAX) - Kindleが落ちなくなって快適! ------ ## 2023\-10\-18(水) ### ファシリ @hiromisugie ### ドライバー @motohiro-mm ### 読んだところ 4-4-3 205p 「Stimulusの機能概要」から 4-4-4 211p 「Lifecycle Callback」まで。 PR: ### 次回 4-4-4 211p 「Data Maps」から。🚂 ### 学んだこと・感想 - @hiromisugie - Stimulusは、JavaScriptをさっと入れるときに使える控えめなフレームワーク、らしい。どこからJavaScriptになっているのかが、まずよくわかっていない。。。 - まずコントローラを作成する。 - 続いてアクション。アクションはDOM内のイベントとコントローラ内のメソッドを紐づける。 - `data-action`の書き方は`イベント名->コントローラ名#メソッド名`という規約。デフォルトイベントが存在するので、イベント名は省略できる - そしてターゲットは、コントローラ内のDOM要素とJavaScriptを関連づける。 ここで完全に頭が付いていけなくなっています。。。JavaScriptの学習とどう平行して理解を進めていくのかよくわかっていませんが、とにかくJavaScriptも学ばねばと思いました。 - @sharoa - クローンじゃなくて、ダウンロードしてきたものをそこに入れるという方法があるんだな、と思った。 - Stimulusの体験として、公式ページに掲載されているサンプルが画面越しに確認できたのは良かった。 - ただ、コードの中身を見るとやはりそこにはJavascriptの子達が。。。(sadanoraさん教えてくれてありがとうございます。) - そもそもDOMってなに?ってところから始まっていて、   - [【JavaScriptの基本】DOMの仕組みと構造](https://tcd-theme.com/2021/05/javascript-dom.html)   - このあたりを見てちょっと勉強したいと思います。   - - @ayu-0505 - Stimulusの機能ではdate-*属性を利用し、それがJavaScript側の各要素と規約で結びついている。 - data-controller,data-action,data-targetを学習した。(が、まだ分からず) - @moegi29 - HTMLのdata-controllerなどdata-*属性とJS側の各要素を紐づけできる。JSの処理を書いてブラウ動きをみるのは楽しい。 - @motohiro-mm - Stimulusは控えめなJavaScriptのフレームワーク - data-* - data-controller:ここで定義されたもの(例:hello)と対応する名前のコントローラを読み込む(hello_controller.js) - data-action:監視するイベントと、イベントが発生した時の処理が書かれる - data-targetはtargetsで定義した文字列と紐づけられる - @sadanora - Stimulusはhtmlのカスタムデータ属性を使ってDOMと接続できる。 - [data\-\* \- HTML: ハイパーテキストマークアップ言語 \| MDN](https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/data-*) - Stimulusは自作サービスで使ったので基本的な使い方は知っているつもりだけど、本だけ読んでいてもピンとこない感じが気持ち悪い。 - フロントエンドの話はJSの話が前提になっている解説も多いので、必要になった時に戻っ読み直すくらいでいい気もする? -----

    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