ASTRO Camp 11th
      • 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
    # 20220817 SCSS、檔案打包、金流系統 ###### tags: `Ruby` `Rails` ## SCSS ### manifest app/assests/stylesheets/application.css *=require_tree . => 會把所有css檔案全部載入進來 *= require_self => 自己也載進來 **沒用到的檔案就砍了**(scss, helper)!! 展現對自己專案的了解 改檔名把application內的移出,再自己手動載入 **建議模組化**: 細分檔案功用, 可以降低Git衝突 ```css /* *= require_self *= require "form" *= require "flash" */ ``` ![](https://i.imgur.com/Rj3rTpE.png =300x) ### SCSS 巢狀結構 SCSS可以有巢狀結構 可以解決CSS的混亂 但這不是標準的css 打包時會自動編譯成標準CSS 巢狀結構: ```css= .field_with_errors { display: inline; input[type="text"] { border: 3px solid red; } } ``` ### SCSS 自訂變數 $ 可以拿來自定屬性,再代入 ```css $error-color: red; .field_with_errors label { color: $error-color; } ``` ### SCSS vs Sass Sass 沒有括號跟分號 Sass 是靠縮排去判定的,所以你只要縮排縮錯了就不會動了。 **當一個工程師,縮排很重要** ### Rails檔案打包歸屬 Assets Pipeline => 交給Ruby做 webpack(er) => 交給node Webpack 工具 Webpacker gem(用webpacker來叫webpack打包) **打包的意義**: **壓縮** - 減少檔案大小省空間,空格、註解都會省略掉,甚至連變數都會一起幫你改成比較少名 反正瀏覽器看得懂就好了 - 減少對server的request, 例如這個網站有500支css, 打包成一支, 就只需要request一次而非500次 ### hand shaking 你來看我網站時,會有握手(hand shaking),確認你的request http1.1 每次都要握手(鼓勵打包) http/2 只握手一次就可以做到平行下載(不鼓勵打包) > https://http2.akamai.com/ > https://http2.github.io/ > https://ithelp.ithome.com.tw/articles/10222189 http/3 正在草稿中 **相關資料:** 維基:https://zh.wikipedia.org/zh-tw/%E6%8F%A1%E6%89%8B_(%E6%8A%80%E6%9C%AF) https://notfalse.net/7/three-way-handshake https://ithelp.ithome.com.tw/articles/10280652 rails 5 Assets Pipleline Webpack(er)標配 rails 6 Assets Pipleline Webpack(er) rails 7 Assets Pipleline importmaps (不用node!!) ### 進行打包 index.js類似入口的意思 index.js中import css檔案 方便一次打包 自己在js開個資料夾 css抓取順序:packs/application.js -> index.js -> 個別資料夾的index.js 分層管理 檔案搬到JS後原來在![](https://i.imgur.com/90ul8UR.png) ```css= /* *= reruire "form" *= require "flash" *= require_self */ ``` 就可以刪除 關鍵字:CSS in JS ## markdown > https://vuejs.org/examples/#markdown 想要在輸入框寫markdown alternative -> 找不到選項時可以找的替代品 vanilla.js -> 超好用,所有大公司都在用它。效能也超好 -> 原生JS npm <---> yarn markdown相關套件 1. [simplemde](https://github.com/sparksuite/simplemde-markdown-editor) 2. [easy-markdown](https://github.com/Ionaru/easy-markdown-editor) 找月曆關鍵字 datepicker 月曆套件: [flatpickr](https://flatpickr.js.org/getting-started/) 後端給前端資訊:例如 用月曆套件 有些天不顯示 可以使用html或是API兩種方式達到目的, 使用的時機 html: 放dataset API: 比較即時 搶票 ## 訂單建立 (串金流) ```rb= rails g model Order serial price:integer state user:belongs_to note:text ``` ### 來去繳費 先成立訂單,再去刷卡 想路徑~~~~ ```ruby! resource :plans, only: [:show] resources :orders, except:[:edit, :update, :destroy] do # 取消訂單 member do delete :cancel end end ``` 接著就是平常的CRUD 訂單編號: ORD-20220817000123 好處是:一看就知道日期跟訂單數 壞處:業績被發現 ### 狀態 - 未付款 unpay - 已付款 paid - 付款失敗 fail - 已取消 cancelled - 已退款 refunded ### 狀態機 state machine ### 可以先畫出關狀態機關係圖 寫在model order.rb ```rb= event 線 do transitions from: 節點 to: 節點 ``` 每過一分鐘,非洲就過了60秒! 人類是可以做很多事情的:像是喝岩漿ㄑ(一生只能喝一次 >///< ) ![](https://i.imgur.com/FTiUBfw.png =200x) 如果直接進資料庫改東西,是會出事的!!!!(就跟突然從四檔拉到R檔一樣0口0) 來裝套件囉!!!來裝套件囉!!!ㄑ! statemachine [AASM](https://github.com/aasm/aasm) ```$bundle add aasm``` order model導入套件 ```ruby include AASM aasm column: "state" do state :pending, initial: true state :paid, :fail, :refunded, :cancelled event :pay do transitions from: [:pending, :fail], to: :paid end event :fail do transitions from: :pending, to: :fail end event :cancel do transitions from: [:pending, :fail], to: :cancelled end event :refund do transitions from: :paid, to: :refunded end end ``` 狀態機會送你方法: 可以去sandbox玩玩看, 以這個order例子來說: order = (serial:'kk' price:100) ?系列:(回傳true false) ```ruby order.pay? order.fail? order.cancel? order.refund? ``` may_可以嗎系列:(回傳true false) ```ruby order.may_pay? order.may_fail? order.may_cancel? order.may_refund? ``` !執行系列:(改變state) ```ruby order.pay! ->state從pending變成paid order.fail! order.cancel! order.refund! ``` 可以在狀態機內再加其他事情,當狀態發生改變,會一起做 ```ruby! event :pay do transitions from: :[:pending, :fail], to: :paid after do puts "發簡訊" end end ``` 工程師的手也伸不進來: ```ruby aasm no_direct_assignment: true do (略) end ``` SecureRandom module可以用方法alphanumeric產生字母數字的字元 secure.alphanumeric

    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