OOZOU
與我們聯繫
返回 TIL 列表
ruby on rails

在 Rails 中為 DOM 產生唯一 ID

October 14, 2020

Rails 有許多很棒的 view helper,其中之一就是 dom_id:

dom_id(Post.find(12))       <em># => "post_23"</em>
dom_id(Post.new)            <em># => "new_post"
language-rails</em>

你也可以提供一個前綴:

dom_id(Post.find(23), :edit) <em># => "edit_post_23"</em>
dom_id(Post.new, :custom)    <em># => "custom_post"
language-rails</em>

Rails 官方文件

更多關於 ruby on rails 的筆記

ruby on railsFebruary 10, 2022

用 Pundit Policy 管理 permitted parameters、預設值與各 action 的參數

要管理 permitted params,你可以在你的 policy 中加入 permitted\attributes 和 permitted\attributes\for\#{action},例如

ruby on railsJanuary 31, 2022

在 Turbo 中用 `requestSubmit` 送出表單

Turbo 會監聽 form 上的 submit 事件。因此,用 JS 送出表單時,請一律使用 requestSubmit。

ruby on railsJanuary 19, 2022

在 GitHub Actions 中讓 Rubocop 與 ESLint 忽略 bundled gems

Rails 專案在 GitHub actions 中通常會把 gems 安裝到 vendor 目錄,方便在後續執行時使用快取。

有專案構想嗎?

我們很樂意聆聽您正在打造的產品。

開始對話hello@oozou.com
OOZOU Logo

曼谷 · 新加坡 · 香港

X
Facebook
Instagram
LinkedIn

服務

  • Web 開發
  • AI 代理人與生成式 AI
  • 行動應用開發
  • 數據分析與工程
  • UI/UX 與產品設計
  • 數位轉型

公司

  • 關於我們
  • 職涯
  • 部落格
  • 案例研究
  • Today I Learned
  • 聯繫我們

更多

  • 產業
  • 合作夥伴網絡
© 2026 OOZOU. 版權所有。
隱私政策行為準則反賄賂反貪腐政策