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列表填充下拉列表。如果我嘗試上述操作,則會收到一條錯誤消息,指出沒有關聯:存在性別。當我使用標準的基於模型的方法嘗試類似的東西時,它就像魅力一樣。
任何想法?我已經通過了幾次文檔,但根本看不到我要去哪裏錯了。