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
    # 【第7週】パRails輪読会🚂 \(2023\-10\-02\~ 2023\-10\-06\) ###### 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\-02(月) ### ファシリ @shodan ### ドライバー @sadanora ### 読んだところ 3-5 「HTTPとRailsアプリケーション」から PR: ### 次回 p164の冒頭から? ### 学んだこと・感想 - @sharoa - HTTPリクエストのおさらいで、ブラウザからWebアプリケーションへリクエストを送った時の手順とブラウザの視点からみた流れの確認ができてよかったです。 - Early Hintsがなんだか難しかった。ざっくり感想となりすみません。 - @shodan - 通常のHTTPリクエストの流れの場合、JSやCSSなどのアセットのリクエストは、レスポンス受信後のHTMLのパースが始まったタイミング。 - ここでアセットのダウンロード待ちなどが発生すると全体の表示完了が遅れてしまう。 - なので、本来のレスポンス(`200 OK`)が来る前に、読み込むアセットのヒントをレスポンスと(`103 Early Hints`)して受け取るという仕組みがある。 - 日本人が提案した仕様ってすごい! - タスクアプリのCRUDを作って動いた!(それでも初心者には大変ですが……)みたいな難しさじゃないパRails……😇 - @moegi29 - 従来のHTTPの仕様ではステータスコードが決まるまでレスポンスを返せなかったけど奥一穂さんという方が作ったEarlyHintsという仕様によって解決された。EarlyHintsに対応したリバースプロキシサーバとしてH2Oというものがある。 - 実際に試しながらやって頂けたので流れがみれて良かったけど難しい。sadanoraさんドライバーありがとうございます。 - @sadanora - Early Hints - 日本人が提案した仕様。すごい! - これまでのHTTPの仕様だとステータスコードが決まるまでレスポンスを返せなかったが、Early Hintsによってステータスコード103で本来のレスポンスを送る前にリソースのヒントを送ることができる。 - 書籍の執筆時点ではまだ主要なブラウザが対応していないので、リバースプロキシを介してEarly Hintsを使うことが現実的だった - https://developer.mozilla.org/ja/docs/Web/HTTP/Status/103 - 現在はchromeやedgeが対応しているが、実験的機能みたい。いまも対応してはいないのか、対応したのかどっちなんだろう? - 久しぶりにドライバーをやったら全然Railsっぽくないことで苦戦してつらかった笑 - @ayu-0505 - EarlyHintsという名前通り、事前にヒントとして「CSSやJSを利用する」とブラウザにお知らせする「103レスポンス返信」機能がHTTPにあることが分かった。 - Railsは上記の機能に対応しているが、ブラウザによっては未対応の場合があり、H2Oというプロキシサーバーを通して利用する。 - これを利用することでアセットのロード開始を早めることができる。 - @hiromisugie - 通常のHTTPリクエストだとHTMLとアセットのリクエストするタイミングが異なること(アセットは後回しになること)を改めて確認できた。 - HTTPのpreloadという仕組みを使うと、ブラウザがHTMLを受け取った直後にアセットのロード開始タイミングを早められる。 - もっと早める方法として、Early Hintsという仕様がある。ステータスコード103として本来のレスポンスを送る前にリソースのヒント(ヒントって何?)を送り、通常レスポンスの200OKの前に103Early Hintsが返ってくる。 - この仕様はまだ未対応ブラウザもあるらしい。 - 実際の画面で確認ができず、難しかった…(sadanoraさんありがとうございます🙏) ------ ## 2023\-10\-03(火) ### ファシリ @motohiro-mm ### ドライバー @sadanora ### 読んだところ 164pから、170p 3章最後まで。 PR: ### 次回 Part 2 Railsの周辺知識 第4章 「フロントエンドの開発手法」から。🚂 ### 学んだこと・感想 - @sharoa - 昨日苦戦していた`early hints`が確認できてよかったです。 - CSPはコンテンツセキュリティポリシーのことで、主にXSSの影響を軽減することを目的とした仕組みのこと。 - CSPを使うと、悪意のある投稿にたいして無効にすることができる。(インラインのJavaScriptなどを無効にすることができる。) - Rails5.2からはCSP用のヘッダーを簡単に設定するための仕組みが用意されている。 - `nonce`を活用してより細かい指定をする。なんだかむずかしい。。。 - @sadanora - CSP - XSSの影響を軽減することを目的とした仕組み - CSPを有効にするにはレスポンスヘッダーに`Content-Security-Policy`ヘッダーを追加する必要がある - CSPによって外部ドメインのJavaScriptファイルが実行できなくなり、インラインのJSも実行されない - GAのようにサードパーティのJSを利用したい場合許可するドメインの設定をする必要がある - report-onlyモード - ポリシーの適用をせず違反内容を指定したURLにJSONを送って報告させることができる - このレポートを確認して、許可したいドメインのJSが弾かれてないかとか確認するってこと...? - nonce - nonceによって、指定したインラインのJSの実行だけを許可できる - 話がどんどん細かくなって、むずかしい... - @moegi29 - `https://localhost:9090/todos`でh2oからEarlyHintsで出力?されているページが見れた!ありがとうございます。 - コンテンツセキュリティポリシーは主にクロスサイトスクリプティングの影響を軽減することを目的とした仕組み。 - XSSの影響を軽減するにはインラインでのJavaScript実行を禁止することが重要。 - nonceでヘッダーで指定した文字列を値としたnonce属性があるscriptタグのみを実行できる。 - @motohiro-mm - CSP:XSSの影響を軽減する仕組み - config/initializers/content_security_policy.rb に設定を書くと使える - コントローラごとに設定することも可能 - nonceを使うとさらに細かい設定ができる - nonce属性のあるものを有効にできたりする - 難しい… - @hiromisugie - CSPはXSSの影響を軽減するための仕組み。悪意あるユーザーがJavaScriptを仕込んできたりするのを防ぐ効果がある。 - JavaScriptを一斉に無効化し、ホワイトリストで読み込んで良いものだけ指定できるという感じ - RailsでCSPを利用する場合は(ということはRailsじゃないフレームワークとかでもCSPという用語・考え方があるってことですね)、`config/initializers/content_security_polucy.rb`で設定できる - CSPの中の仕組みの1つとして`nonce`というのがあり、nonce属性があるscriptタグのみ実行できるようになるらしい。 - 唐突に「簡単ですね」と出てきて、簡単じゃない、と思った笑。パRailsは、ちょいちょい文体に「これくらいは行けるよね?」という圧を感じることがある😅 - Railsを学ぶためのいろいろなリンクを確認。かの有名なRailsチュートリアル、自分はやったことがないのでどこかのタイミングでやりたいとは思っている…(やった方いらっしゃいますか、どうでしたか?) ------ ## 2023\-10\-04(水) ※あたらしいリポジトリを作成したりなどで読めていないです。 ### ファシリ ### ドライバー ### 読んだところ PR: ### 次回 ### 学んだこと・感想 ----- ## 2023\-10\-05(木) ### ファシリ @sharoa ### ドライバー @moegi29 ### 読んだところ 4章 「フロントエンドの開発手法」から 4-1-2 「Webpackerの基本的な動作」の途中まで。 PR: ### 次回 4-1-2 174pの途中(ビルドが完了すると~)から。🚂 ### 学んだこと・感想 途中の`webpacker:compile`ができなくて みんなで原因を考えていた。 ----- ## 2023\-10\-06(金) ### ファシリ @hiromisugie ### ドライバー @motohiro-mm ### 読んだところ 4-1-2 174pの途中(ビルドが完了すると~)から 177p の4-1-3の前まで。 PR: ### 次回 4-1-3 「Webpackerの設定ファイル」から。🚂 ### 学んだこと・感想 - @sharoa - `webpacker`って曲者??というイメージしかいまのところ無いですw - そして、まだRailsがよくわかっていないのに、JavaScriptまで登場してきて、ちょっとほんと難しいですね。 - なので、また読み返したいと思います。 - 感想のみになってすみません。 - @hiromisugie - Webpackerの設定の沼が深くてまだ理解できていないけど、ひとまず先に進めそうで良かったなという気持ち…! - そもそも、Webpackerのエントリーポイントというものが何なのか、どういう役割なのかがわかっていない…。「エントリーポイント」というくらいだから、何かしらの動作が始まる場所、というようなことなのかな、JavaScriptのこともわかってないので今は「ふむふむ…」で進もうかなと思います。 - RailsでjQueryを使う際にエントリーポイントからjQueryを読み込む、ということは朧げながらわかった。それ以外に、自作したjsのプログラムを盛り込む場合にもエントリーポイントで設定するらしい。ふむふむ… - @ayu-0505 - まだ自分の学習としてはRailsの基本を理解している段階なので、この章はJS(フロントエンド)も関係してきて難しいなと感じました。 - 調べたところwebpackerはRails7で廃止?しているようなので、「使いこなせるようになる」というよりは、仕組みを理解するに重点を置く方が良いのか? - @moegi29 - 'webpacker:compile'でjsに対応したビルド結果のファイルが生成されている様子をみれてよかった - 'webpacker'はほんとに曲者。。。 - @sadanora - エントリーポイントの読み込み - `sprockets`は`javascript_include_tag` - `webpacker`は`javascript_pack_tag` - `webpacker`がコンパイルしたファイルを確認できてよかったです。 - @motohiro-mm - app/javascript/packsにあるファイルがエントリーポイントになる - app/javascript/packs/application.jsをビルドした結果が、app/public/packs/application-xxx.jsになっている - エントリーポイントを読み込むには`<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>`と書く - エントリーポイントからファイルを読み込むにはapp/javascript下にファイルを置いてそれに書き込む - app/javascript/packs/application.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