I am uploading multiple images (4 file fields) using paperclip, which is working fine just fine and dandy but I want to also attach a description to 3 of the 4 file fields. So far I have created a model called “Asset” which has the following:
class Asset < ActiveRecord::Base
belongs_to :project
has_attached_file :asset
end
My project model is aware of the assets and has_many assets:
class Project < ActiveRecord::Base
validates :title, :presence => true
has_many :assets
accepts_nested_attributes_for :assets
end
And in my _form.html.haml I am creating 4 fields like so:
- number = 0
= f.fields_for :assets do |asset|
%ul.fields
%li= asset.label :asset, "File ##{number += 1 }"
%li= asset.file_field :asset
And of course my projects_controller.rb contains the following to build the 4 fields:
def new
@project = Project.new
4.times { @project.assets.build }
end
My questions are, where is the best place to put this “description” for each of the fields, the assets or projects? My second one is how do I not render a description field for the last one in the loop but do in fact render a description field for the first 3?
a quick way would be to just put