![](/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.