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
OOZOU Co., Ltd.
548 One City Centre
Ploenchit Road
Bangkok 10330
Thailand
+66 2544 0000
hello@oozou.com

服务

  • Web 开发
  • AI 智能体与生成式 AI
  • 移动应用开发
  • 数据分析与工程
  • UI/UX 与产品设计
  • 数字化转型

公司

  • 关于我们
  • 加入我们
  • 博客
  • 案例研究
  • Today I Learned
  • 联系我们

更多

  • 行业
  • 合作伙伴网络
© 2026 OOZOU. 版权所有。
隐私政策行为准则反贿赂反贪腐政策