确保 ActiveInteraction gem 已被正确安装。
检查您的验证器代码是否正确,例如:
class MyInteraction < ActiveInteraction::Base
bool :my_boolean
validate :my_validator
def my_validator
errors.add(:my_boolean, "cannot be true") if my_boolean
end
end
result = MyInteraction.run(my_boolean: true) #=> result.errors.full_messages => ["My boolean cannot be true"]
class MyInteraction < ActiveInteraction::Base
include ActiveModel::Validations
bool :my_boolean
validates :my_boolean, exclusion: { in: [true] }
end
这将在运行交互时自动执行验证器,并将错误保存在 result.errors
中。
上一篇:ActiveForm未加载