AstroCamp 6th
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • Make a copy
    • Transfer ownership
    • Delete this note
    • 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 Help
Menu
Options
Engagement control Make a copy 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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    # 1113_ruby_day6 [![hackmd-github-sync-badge](https://hackmd.io/EOFrEBNKTSiSGJVlmjhzmA/badge)](https://hackmd.io/EOFrEBNKTSiSGJVlmjhzmA) --- #### 上課日期:1113 ###### tags: `ruby` ###### tags: `5xruby` --- # 相關連結: - [課程影片](https://campus.5xruby.tw/courses/1136422/lectures/25361517) --- # 0. 綱要/目錄 - [ ] rails 專案 - [ ] 新增 - [ ] 修改 - [ ] 刪除 - [ ] 作業 --- # 1. rails 專案 ##### manifest file 清單文件 - 被用來定義擴展或檔案打包相關數據 - 減少檔案的大小和require的數量 - 註解等訊息都會被壓縮 ![](https://i.imgur.com/28I7VUg.png) - `require_tree .`,一種便捷的寫法(龍哥:偷懶),表示以下的東西都require - 應該直接寫明需要require什麼項目才好,這樣可以清楚知道到底用什麼 ##### - [Asset Pipeline 說明](https://ihower.tw/rails/assets-pipeline.html) ##### - [前端工具:webpack](https://webpack.js.org/) - Rails 6 開始支援 - 5之前為asset pipeline --- - note: 當東西越來越多的時候,要將其中一些模組化。不但可以整理版面,也可以讓其他地方拿來用。 - note: 局部渲染(不是完整的檔案),前面檔名有底線, ##### meta programming - 用程式碼來寫程式 - 舉例:用一台3D印表機製作出一台印表機的零件(然後將其組裝起來)=> 用印表機印出印表機 - 在alias(別名)裡面會設定相關的名稱,類似關鍵字的模糊比對,通常會包含該方法的各種變化。 --- - Board.find(1) #只會找到一筆資料,只能數字 - Board.find_by(id: 2) #只會找到一筆資料,可以接hash - Board.where(id: 3) #會找到一組資料(陣列) - Board.all #會找到一組資料 #### 面試題:find跟find_by差在哪? - 找到資料有差 - 錯誤訊息也不同 - 相近的另一種方法:find_by! <-加一個驚嘆號 --- ##### 錯誤訊息的處理方法 在Controller裡面: `rescoue_form ActiveRecord::RecordNotFound, with: ABC ` => 只要在這個Controller出現ActiveRecord::RecordNotFound這個錯誤訊息,就會用with後面的ABC方法來處理。接著在下方定義ABC。 - 這種方法通常不會公開,會放在下方的private裡面 - 比較好的方式是,讓它連結到404頁面 - rails會有一個內建的404頁面,放在public下面 - 放在public下面的,不需要經過MVCR的處理 - 404頁面,其實是一個很好的廣告/導覽頁面,因為使用者會好好看這一頁。 --- note: create 和 update 因為流程上很像,所以code也長得很像 note: new 和 edit 因為流程上很像,所以code也長得很像 ##### unobtrusive javascript 非侵入式JavaScript - 不要將JS綁在html裡面 --- - php的laravel(2011)模仿自rails(2004) ##### before_action - 在action之前就先執行,這樣可以減少後面action中同樣的程式碼 - before_filter同義,是較早的版本 ##### 局部渲染 - 要注意不要有 "@" 實體變數,讓它主動去抓資料產生變化。而是讓它被動(的提供內容) - note: 省略時,要注意 對應到的資料是否唯一/常用。 - note: 在rails裡,沒有特別註明格式,預設為html --- # 作業 本週 Ruby 作業練習: - 開一個全新的 Rails 專案 - 手工撰寫針對 Book 的 CRUD 功能 - Book 有書名跟售價兩個欄位 - 邊講解邊錄影,錄影上傳到 Youtube - 儘量把時間壓在 30 分鐘內 - 11/17(二)10:00 前交件

    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