現在、Rails 3.2 と Carrierwave を使用しています。
複数のファイルをセットアップしていますが、複数のファイル フィールドが必要ですが、必要なファイル フィールドは 1 つだけです。ブラウザが HTML5 の multiple プロパティをサポートしていない場合、これをデフォルトとして提供します。
コントローラ
def new
@ad = Ad.new
5.times { @ad.images.build } // provides multiple file fields in the view.
end
def create
ad = Ad.new(params[:ad])
user = User.find(session[:user_id])
if user.ads << ad
flash[:notice] = "Ad successfully saved."
redirect_to ad_listing_path(ad.id, ad.slug)
else
render :new, :alert => "Ad was not saved."
end
end
意見
<%= f.fields_for :images do |a| %>
<% if a.object.new_record? %>
<%= a.file_field :image, :multiple => true %><br>
<% end %>
<% end %>
が複数のフィールドを提供している場合5.times { @ad.images.build }
、複数を受け入れる 1 つのファイル フィールドを表示する適切な方法は何ですか?