Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个用改革宝石创建的表格。
我有一个变量,它是一个 id 数组,因此更新此变量以填充数据库中的对象的任务。
如何使用干式创建自定义强制来执行此操作?我没有在文档中找到自定义类型的示例。
改革可以使用干式强制。这将覆盖设置器,强制值并调用原始设置器。您不必为您的用例创建自定义强制。请参见下面的示例。
在您的 Gemfile 中包含以下 gem
gem 'dry-types'
下面的代码进入你的表单类说 form.rb
require 'reform/form/coercion' class Form < Reform::Form property :ids, type:Types::Coercible::Array.member(Types::Form::Int) end