1
我想实现嵌套使用reform宝石。我有三个型号:Rails 4与改革创业板和simple_form
- 客户(belongs_to的:personal_details)
- PersonalDetail(belongs_to的:标题)
- 标题(的has_many:PersonalDetail)
我试图创建一个使用一个CustomerForm使用以下代码改革宝石:
/app/forms/customer_form.rb
class CustomerForm < Reform::Form
property :national_id
validates :national_id,
:presence => true
property :personal do
property :first_name
property :title
validates :first_name,
:presence => true
end
end
/app/controllers/customers_controller.rb
def new
@form = CustomerForm.new(Customer.new(personal: Personal.new))
end
/app/views/customers/new.html.haml
= simple_form_for @form, :url => customers_path do |f|
= f.input :national_id
= f.simple_fields_for :personal do |builder|
= builder.input :first_name
= builder.association :title
= f.button :submit, "Submit"
:title属性将不会收到任何inpu t在表单提交期间。 Title和PersonalDetail之间的关系仅用于使用Title.name列表填充下拉列表。如果我尝试上述操作,则会收到一条错误消息,指出没有关联:存在性别。当我使用标准的基于模型的方法尝试类似的东西时,它就像魅力一样。
任何想法?我已经通过了几次文档,但根本看不到我要去哪里错了。