I am currently using acts_as_attachment to upload multiple images in a
form. I can currently edit all the info in the form but not the images
associated with each record. How would I go about doing this?
Equipment has_many :images
Image belongs_to :equipment
My Controller Looks Like This:
def new
@equipment = Equipment.new
@image1 = Image.new
@image2 = Image.new
@image3 = Image.new
@image4 = Image.new
end
def create
@equipment = Equipment.new(params[:equipment])
@image = @equipment.images.build(params[:image1])
@image = @equipment.images.build(params[:image2])
@image = @equipment.images.build(params[:image3])
@image = @equipment.images.build(params[:image4])
if @equipment.save
flash[:notice] = ‘Equipment was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end
My New Equipment Form is set up like this:
<%= error_messages_for :equipment %>
<%= error_messages_for :image %>
New equipment
<% form_tag ({:action => ‘create’}, :multipart=> true) do %>
Category
<%= select :equipment, :category, ['Choice 1', 'Choice 2', 'Choice
3' ] %>
Year
<%= select :equipment, :year, ['Choice 1', 'Choice 2', 'Choice 3' ]
%>
Make
<%= select :equipment, :make, [ 'Choice 1', 'Choice 2', 'Choice 3' ]
%>
Model
<%= text_field 'equipment', 'model' %>
Serial Number
<%= text_field 'equipment', 'serial_number' %>
Hours
<%= text_field 'equipment', 'hours' %>
Price
<%= text_field 'equipment', 'price' %>
Description
<%= text_area 'equipment', 'description', "rows" => 7, "cols" => 23
%>
Upload Image 1
<%= file_field :image1, :uploaded_data %>
Upload Image 2
<%= file_field :image2, :uploaded_data %>
Upload Image 3
<%= file_field :image3, :uploaded_data %>
Upload Image 4
<%= file_field :image4, :uploaded_data %>
Status
<%= select :equipment, :status, ['For Sale', 'Sold'] %>
<%= submit_tag “Create” %>
<% end %>
<%= link_to ‘Back’, :action => ‘list’ %>
Uploading images when creating a new record works flawlessly but as
stated I can not get the edit function to work for the images. Any
help would be appreciated.
Thanks,