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

不透過 HTTP 將檔案附加到 ActiveStorage

October 13, 2020

如果你想附加一個在磁碟上產生的檔案,或是從使用者提交的 URL 下載下來的檔案,可以這樣做。

@model.image.attach(
    io: File.open('/path/to/file'),
  filename: 'file.pdf',
  # content type is optional
  content_type: 'application/pdf'
)

更多關於 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. 版權所有。
隱私政策行為準則反賄賂反貪腐政策