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
    # 1109_ruby_day5 [![hackmd-github-sync-badge](https://hackmd.io/MZ8ySDMMQUmc_-MMZq2Dvw/badge)](https://hackmd.io/MZ8ySDMMQUmc_-MMZq2Dvw) --- #### 上課日期:1109 ###### tags: `ruby` ###### tags: `5xruby` --- # 相關連結: - [課程影片](https://campus.5xruby.tw/courses/1136422/lectures/25361517) --- # 0. 綱要/目錄 - [ ] 1. Board / route / controller - [ ] 2. Rails的格式與操作 - [ ] 3. 附錄 --- # 1. Board / route / controller ### 安裝 / bundler / gemfile `$ rails g model Board title` - 學習框架就是學習慣例 - 在vscode裡,若要固定將__.html.erb檔改成是html格式,找到此行做修改即可。 (或者也可以逐次在檔案裡修改) ``` "emmet.incloudLanguage": { "erb": "html" } ``` ## controller裡的實體變數 在不同的def裡面,實體變數即使外貌一樣,仍視為不同動作下的結果,該動作結束後實體變數就消失。 - controller不要放會重複的東西 ## 參數傳遞 ```ruby= GET /boards?id=2&name=3&cc=4 params = { "id" => 2, "name" => 3 } POST /boards params = { "title" => 'ccc', "ccc" => "ddd" } ``` :::info #### 面試題:get跟post有什麼不一樣? - 主要的不同,傳送方式不一樣,只是post稍微安全一點。除非進行加密。 - get:將參數(帳號密碼)在路徑裡面傳送(變成明碼),會出現在網址上,在瀏覽紀錄裡面看得到 - post:將參數放在php的requist body裡面傳送。 - 兩者傳送資料的型態不同,因此post送出後頁面重新整理會出現提示![](https://i.imgur.com/ICUNMpK.png) ::: #### params - 像是hash。 - 資料送到後端的過程,可用params去拿值,它會拿出類似hash的值(是rack幕後做的打包動作)。 #### 網址說明 網址:`http://localhost:3000/boards/new?id=2&name=?3#aaa` * `http://` - protocal * `localhost` - hostname/ domain name * `:3000/` - port (http預設是80,https預設是443) * `/boards/new` - path-> route.rb 路徑(連結到哪個頁面) * `?id=2&name=?3` - querystring查詢字串 -> 在rails裡是params的一部分 * `#aaa ` - 錨點aaa - 延伸閱讀:[URL(wiki)](https://en.wikipedia.org/wiki/URL) - 範例: ![](https://i.imgur.com/QQAnxNu.png) - 帳號密碼可在本機的瀏覽器裡看到,network > name_sign_in > ... ### SASS/SCSS - CSS的不同寫法 - [介紹文1](https://medium.com/andy-blog/day05-%E8%AE%93css%E4%B8%8D%E5%86%8D%E9%9B%A3%E8%AE%80-scss-6e46261a42b5) - [介紹文2](https://tw.alphacamp.co/blog/css-preprocessor-sass-scss) - [vscode裡的連結](https://sass-lang.com/) --- # 2. Rails的格式與操作 ## 2.1. 為何明明沒寫,可是頁面卻仍然有html的樣式內容? > rails會將每個網頁共同的地方拉出來放 1. 理論上每個html.erb檔,都會有自己的layout,但如果沒有就會依application.html.erb檔的格式,所以又稱它為「預設全站的公版格式」。 > 如果要了解views的html.erb檔,可至views裡的layouts看application.html.erb檔即可知道。 > ![](https://i.imgur.com/D0St5J7.png) 2. 因為是公版格式,可以在此設定表頭或是註腳(footer) --- ## 2.2. 在rails裡更改css樣式表? > SCSS、SASS 1. 如果想在rails裡更改css樣式表,有提供scss的格式,相關技巧寫法可看以下連結。 - [介紹文1](https://medium.com/andy-blog/day05-%E8%AE%93css%E4%B8%8D%E5%86%8D%E9%9B%A3%E8%AE%80-scss-6e46261a42b5) - [介紹文2](https://tw.alphacamp.co/blog/css-preprocessor-sass-scss) - [sass-lang](https://sass-lang.com/) 2. 更改的檔案,是在app/stylesheets/boards.scss檔案裡,如下圖: ![](https://i.imgur.com/cnPgQAl.png) --- # 3. 其他補充網站 - [buildwith](https://builtwith.com/):查詢網站使用哪些技術 - [hash裡包hash的寫法與詳解](https://apidock.com/rails/ActionController/Parameters/permit)(承豪提供)

    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