![](/img/trans.png)
[英]How do I get nested_form to work with Formtastic in Rails 3.1?
[英]How do I get a nested form working with formtastic?
每当我执行以下操作时,它将不会在表单上显示任何子字段:
= f.semantic_fields_for :transfers do |g|
如果我将其单数化,它们会显示出来,但模型不知道该如何处理:transfer
。 我尝试为使accepts_nested_attributes_for
匹配使用单数形式,但是那也不起作用。
交易:
has_many :transfers
accepts_nested_attributes_for :transfers
传递:
belongs_to :transaction
视图:
= semantic_form_for [@user, @transaction], url: url, style: "width: inherit;" do |f|
= f.semantic_fields_for :transfers do |g|
= g.inputs do
= g.input :amount
%li
%label
= "(#{Transfer::TRANSFER_FEE.format :symbol} transaction fee will be added)"
= g.inputs do
%li
%label
Click
%input{ type: "image", value: "submit", style: "vertical-align: middle;",
src: "https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" }
or fill in your credit card information below
= g.inputs do
= g.input :first_name
= g.input :last_name
= g.input :card_type, as: :select, collection: [["Visa", "visa"], ["MasterCard", "master"], ["Discover", "discover"], ["American Express", "american_express"]]
= g.input :card_number
= g.input :card_verification
= g.input :card_expires_month, as: :select, collection: (1..12)
- year = Time.now.year
= g.input :card_expires_year, as: :select, collection: (year..(year+25))
= f.inputs do
%li
%label
%input{ type: "submit", value: "Buy", name: "use_cc" }
问题是我没有建立传输对象。
在控制器中
@transaction = current_user.transactions.build
@transaction.transfers.build
我没有添加第二行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.