karlley
    • 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
    # 小ネタ 輪読会での小ネタを集めました。 ## コマンドライン * `cd -` で前にいたディレクトリに戻る * `ctrl + r` でコマンドのヒストリー検索を行える ## Git/GitHub * `git checkout .` で変更点を戻せる * `git switch -c branch_name` ブランチ作成 → 作成したブランチに切替 * `git push origin @` で今のブランチでpush * `git remote -v`: リモートブランチを出力 * `git diff --cached`: add後に差分が見れる * push先のURLはターミナル上に表示される * GitHub上で`.` でweb版vscodeが開く * `git diff --cached` or `git diff --staged` でadd後の差分が見れる ## irb * `irb -r path`: irb起動時に`require` も行う * `_` で直前の返り値が表示される * `load 相対パス` を打つとそのファイルを読み込んでくれる * `p` メソッドは`nil` も出力してくれる * `pp` メソッドを使うと出力を見やすく表示してくれる ## railsコンソール * `gem info -e rails`: Gemのインストール状況が確認できる * `rails c --sandbox` でコマンド終了時にDBに対する更新処理をロールバックする * Rails consoleはファイル読み込んだirb * `rails about` でRailsの情報を出力 * `rails c` で`hoge.all` は取得に時間が掛かる(データ件数の数によって注意する) * Railsコンソールで`reload!` で再読み込み * `モデル名.column_names` でカラム名を出力できる * rails系コマンドは`bin/rails` はいつも省略している * 古いアプリは`bin/rails` がないと動かないこともあるらしい * `rails db:migrate:status`: 現在のマイグレーション状態を出力 * どこまでテーブルが作られているのか確認して作業を進めると良い * Railsコンソールで`link_to` ヘルパーを確認する ```ruby helper.link_to '一覧', app.books_path => "<a href=\"/books\">一覧</a>" ``` * `rails routes` で表示される`(.:format)` はアクションが返すファイル形式の指定(フォーマット指定) * `.:`: ドットは拡張子でコロンは動的なものを表すplaceholder * rails ~系コマンドは内部的にRakeが動いている * `book.methods.grep(/up/)` のようにgrep を使ってメソッドを絞り込める(methods の出力結果が配列だから) * `rails notes` でコード内の特定のコメントを取得できる * `rails stats` でRailsアプリの規模感が分かる * `app.Prefix名` でルート設定したURIが表示できる * `rails routes | grep 'string'` でroutesを文字列で絞り込める ## DevTools * `Network` タブ内でHTTPのリクエスト内容の詳細が確認できる * [Chrome DevToolsの使い方 \| FJORD BOOT CAMP(フィヨルドブートキャンプ)](https://bootcamp.fjord.jp/articles/64) ## Ruby * `foo`、`bar` などはメタ変数と呼ばれる * [RFC 3092 \- Etymology of "Foo"](https://datatracker.ietf.org/doc/html/rfc3092) * `null` はRubyだと予約語ではないので変数名として使える * `(&:id)` はあんころのおまじない * チェリー本p114 ## Rails * `class` は予約後なので`klass` になっている * Git管理せずにRails newするには`G` オプションを付与する * [【Rails】Git管理せずにRails newしたい \- 時々とおまわり](https://karlley.hatenablog.jp/entry/2023/05/20/095016) * イーガーローディング系メソッド、N+1問題 * [ためして分かる、N\+1問題とその解決方法 \- プログラミング漫遊記](https://haruguchi-yuma.hatenablog.com/entry/2022/12/23/121820) * ルーティングをブラウザで確認するには`http://localhost:3000/rails/info/route` にアクセスする * `add`とか`before_xxx`とかは大体メソッドで、`()` を省略して呼び出してるだけ * 今何のコンポーネントを学んでいるか意識することが大事 * Railsのディレクトリ構成を理解しているかが大事 * 構成を理解していると規模が大きいアプリでも理解しやすい ## DB * SQLite3のdbコンソールの終了コマンド ```sh .exit .quit ctrl + D ``` * dbコンソールのコマンドミスったら`; `で抜ける * `ORDER BY` 無しのSQLは順不定で出力される * [現場Rails \#2 / 🍒 / Railsのtakeメソッドについて調べて面白かった \| FBC](https://bootcamp.fjord.jp/reports/70853#comment_127910) ## その他 * `routes` は「ラウツ」 * [routes\.rb の読み方は「ルーツ」じゃない!! \- Qiita](https://qiita.com/RyuGotoo/items/86e2e53cd3383bb0a618) * `|` は「パイプ」 * Railsties は「レイルティーズ」 * `_` は「アンダースコア」「アンスコ」 * numericalityは「ニューメリカリティ」 * confirmationは「コンファメーション」 * Ajaxは「エイジャックス」 * コード内のコメントに関し学べる本 * [Clean Coders: Level up your code\.](https://cleancoders.com/) ## 環境構築 * Rubyインストール時にBUILD FAILEDが出た時の対処 * [M1 macでRubyインストール時のBUILD FAILEDエラーの解決法 \- 時々とおまわり](https://karlley.hatenablog.jp/entry/2023/01/31/193144) * `rails s -b 0.0.0.0`: 仮想マシンが持っている全てのネットワークインターフェースにバインディングされるため、仮想環境外部からアクセスできる * `rails new` はオプション無しだとDBにSQLite3が指定される * Railsアプリケーションの生成時のDBの指定 * SQLite3: `rails new hoge` * postgres: `rails new hoge -d postgresql` * railsバージョンを指定しないで`rails new`すると、手元のrubyバージョンに対して入っているrailsの最新バージョンになるっぽい * `rails new` 後のDB作成について * SQLite3はdatabase.ymlが自動生成される * SQLite3以外のDBは`rails db:create` で`database.yml` が生成される ```sh rails new ... (rails db:create)← SQLite3以外のDBはこれが必要 rails db:migrate ``` * `rails new` にoオプションを付けるとRailsでActiveRecordを使わないで動作できる * [コマンドラインツール \- Railsガイド](https://railsguides.jp/command_line.html#bin-rails-notes) * 初ドライバーがやること * ローカルの作業スペースの作成 * `git clone` * アプリのディレクトリに移動 * `bundle install` * sqlite3以外の場合はここで`rails db:create`?(自信がない...) * `rails db:migrate` * `rails s` でアプリ起動確認

    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