Formtasticを使用して複数のレコードを個別に編集する場合は、RyanB's Railscastで扱うことができますか? Formtasticは、RyanBのメソッドが依存するform_tagを使用しません。Railscast 198、formtasticを使用
答えて
semantic_form_for
は、同じパラメータを使用できるように、form_for
のラッパーです。ここでは、formtastic
で同様form_for
ヘルパーを使用することができますので、予めご了承ください
views/products/edit_individual.html.erb
<% semantic_form_for :update_individual_products, :url => update_individual_products_path, :method => :put do |f| %>
<% for product in @products %>
<% f.fields_for "products[]", product do |ff| %>
<h2><%=h product.name %></h2>
<%= render "fields", :f => ff %>
<% end %>
<% end %>
<p><%= submit_tag "Submit" %></p>
<% end %>
views/products/index.html.erb
<% semantic_form_for :edit_individual_products, :url => edit_individual_products_path do %>
<table>
<tr>
<th></th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
</tr>
<% for product in @products %>
<tr>
<td><%= check_box_tag "product_ids[]", product.id %></td>
<td><%=h product.name %></td>
<td><%=h product.category.name %></td>
<td><%= number_to_currency product.price %></td>
<td><%= link_to "Edit", edit_product_path(product) %></td>
<td><%= link_to "Destroy", product, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<p>
<%= select_tag :field, options_for_select([["All Fields", ""], ["Name", "name"], ["Price", "price"], ["Category", "category_id"], ["Discontinued", "discontinued"]]) %>
<%= submit_tag "Edit Checked" %>
</p>
<% end %>
のformtasticバージョンです。
更新
あなたにも、それは部分的なフォームにfields_for使用して、箱から出して動作するはずネストされた属性を使用したい場合。
<%= f.fields_for :comments do |cf| %>
<%=render 'comments/fields', :f=>cf%>
<%end%>
とmake:あなたはのような製品の_fields.html.erbに関するコメントを編集することができます
product.rb
has_many :commments
accepts_nested_attributes_for :comments
を:railscast例に固執し、それを言うことができますコメントビューにフィールドが部分的に表示されていることを確認してください。
華麗な、ありがとう!私はこれをRyanの複数の編集に関するチュートリアルに適用し、edit_multipleビューをレール3に更新しました。このような非安定コントローラのアクションとメソッドへのパスを手動で記述しなければなりませんでした: '= semantic_form_for:isbn、:url {@ controller => 'isbns'、:action => 'update_multiple'}、:html => {:method =>:put} do | f | ' ここでaccepts_nested_attributes_for私は笑っている... – snowangel
ネストされた属性でそれを使用する方法を私の答えに更新しました。 – dombesz
どのようにあなた!私はそれを働かせることはできません。私はあなたにこの新しい質問[リンク](http://stackoverflow.com/questions/6623389/accepts-nested-attribute-for-and-multiple-edits)に関する私のコードを見て勝つことができますか?私はあなたの助けに感謝します。 – snowangel
- 1. FormtasticベースエラーFormtasticドキュメントで
- 2. railscast 197 how to:function add_fields
- 3. Ruby on Rails:トークンフィールド - railscast
- 4. Formtastic label_method
- 5. formtastic - accepts_nested_attributes_for
- 6. マージンはアウトカムエラーを予測するr(198)
- 7. Formtasticを使用してカスタムラベルをチェックボックスに割り当てます。
- 8. 2つのオブジェクトでform/formtasticを使用する際の問題
- 9. Formtastic Nesting Help
- 10. Formtastic Collection Selectドロップダウン
- 11. formtastic-bootstrapのインストール
- 12. Formtasticのヘルプ
- 13. Formtasticのオートコンプリート
- 14. ルビー - formtastic - フォームクラス
- 15. は、ActiveRecordモデルでのみ使用できるformtasticフォームですか?
- 16. シンプルフォームの代わりにforetmを使ってformtasticを使用する
- 17. Remind Me(エピソード274)のOmniAuth RailsCast(エピソード275)
- 18. Formtasticラジオボタンの問題
- 19. JavaScript(Form Builder)のFormtastic
- 20. Formtasticはオンザフライで正しいフィールドを作成しますか?私は<a href="https://github.com/justinfrench/formtastic" rel="nofollow">Formtastic</a>を使用してもaccepts_nested_attributes_forを使用しています
- 21. NilClassの未定義メソッド `model_name ':クラス(Rails 3.0.3、Ruby 1.9.2でformtasticを使用)
- 22. PHPをutf8(195 134)から198に変換する
- 23. Formtastic配列の入力
- 24. FormtasticのデフォルトCSSは、Firefoxの
- 25. 未定義のメソッドFormtastic
- 26. rails3-jquery-autocompleteリファレンスIDとformtastic
- 27. 結合テーブルのFormtasticカスタムフィールド
- 28. Formtastic /レールの形は私が入ることができるフォームを作るためにformtasticを使用しようとしています
- 29. 私は範囲フィールドでactiveadmin使用していますactiveadminとformtastic
- 30. chetboxを出力するformtastic ajaxオートコンプリート
通常のフォームヘルパーはformtasticフォーム内で使用できます。 – dombesz
ジャスティン・フレンチェルによるとform_tagではありません。[link](http://groups.google.com/group/formtastic/browse_thread/thread/887f476fcc901eef) "Formtasticはform_tagと併用できません。" – snowangel