我有问题。我在我的 Rails 应用程序中使用了带有一些复杂表单的改革 gem。不幸的是,我在创建表单时卡住了。那是我的代码:
class Order::Form < Reform::Form
include Coercion
include Composition
include Reform::Form::ActiveRecord
property :subscription, on: :order
property :due_date, type: Date, on: :order
property :start_fee, numericality: true, on: :order
collection :products, populate_if_empty: Product, on: :order do
property :type
property :budget
end
property :campaign, on: :order do
property :customer_id
property :customer do
property :id
property :organization_number
end
end
model :order
def persist!(params)
if validate(params)
binding.pry
# begin
::ActiveRecord::Base.transaction do
save do |data, map|
...
end
end
# rescue Exception
# false
# end
end
end
end
当我尝试保存时,我收到此错误:
NoMethodError - undefined method `to_hash' for #<#<Class:0x007f984ddef6d8>:0x007f984a65a4>
我想知道我是否使用嵌套模型正确配置了组合。