我reform-rails
第一次尝试使用 gem 进行改革。我正在尝试将其用作表单对象,进行一些验证,然后将其保存到数据库中。当我尝试指定验证时,即使我尝试了它自己的一个示例,它也会给出错误。
宝石文件:
gem 'reform'
gem 'reform-rails'
gem 'dry-validation'
配置/初始化程序/reform.rb
require 'reform/form/dry'
Reform::Form.class_eval do
feature Reform::Form::Dry
end
Rails.application.config.reform.validations = :dry
应用程序/表格/album_form.rb:
class AlbumForm < Reform::Form
feature Reform::Form::Dry
property :name
validation do
required(:name).filled
end
property :artist do
property :name
validation do
required(:name).filled
end
end
end
命令行:
AlbumForm.new(Album.new)
Traceback (most recent call last):
3: from (irb):1:in `<main>'
2: from app/forms/album_form.rb:1:in `<main>'
1: from app/forms/album_form.rb:6:in `<class:AlbumForm>'
ArgumentError (wrong number of arguments (given 1, expected 0))
第 6 行是validation do
. 我错过了什么吗?