私は Rails のネストされたフォームにまったく慣れていないので、おそらくここで何かを忘れていたと思います。私は、article
多くのassets
(ペーパークリップの添付ファイル)があるペーパークリップチュートリアルに従っています
私が立ち往生している部分は、article
コントローラーで複数のファイルアップロードフィールドを作成することです。
アセット モデルを下部近くに追加した部分的なフォームが表示されます。
<%= form_for(@article) do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br>
<%= f.text_area :content %>
</div>
<%= f.fields_for :asset do |asset| %>
<%= asset.file_field :image %>
<% end %>
<div class="actions">
<%= f.submit %>
<% end %>
アーティクル コントローラーでは、フォームのその部分を 5 回ビルドすると思われるものを追加しました。
def new
@article = Article.new
5.times {@article.assets.build}
end
参考までに、記事とアセット モデルを次に示します。
論文
class Article < ActiveRecord::Base
has_many :assets
end
資産
class Asset < ActiveRecord::Base
belongs_to :article
has_attached_file :image,
:style => {
:thumb => '150x150#',
:medium => '300x300>',
:large => '600x600>'
}
end
私は何が欠けていますか?