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 %>
<h1>New equipment</h1>
<% form_tag ({:action => ''create''}, :multipart=>
true) do %>
<p id="category"><label
for="equipment_category">Category</label><br/>
<%= select :equipment, :category, [''Choice 1'',
''Choice 2'', ''Choice
3'' ] %></p>
<p id="year"><label
for="equipment_year">Year</label><br/>
<%= select :equipment, :year, [''Choice 1'', ''Choice
2'', ''Choice 3'' ]
%></p>
<p><label
for="equipment_make">Make</label><br/>
<%= select :equipment, :make, [ ''Choice 1'',
''Choice 2'', ''Choice 3'' ]
%></p>
<p><label
for="equipment_model">Model</label><br/>
<%= text_field ''equipment'', ''model''
%></p>
<p><label for="equipment_serial_number">Serial
Number</label><br/>
<%= text_field ''equipment'',
''serial_number'' %></p>
<p><label
for="equipment_hours">Hours</label><br/>
<%= text_field ''equipment'', ''hours''
%></p>
<p><label
for="equipment_price">Price</label><br/>
<%= text_field ''equipment'', ''price''
%></p>
<p><label
for="equipment_description">Description</label><br/>
<%= text_area ''equipment'', ''description'',
"rows" => 7, "cols" => 23
%></p>
<p><label for="equipment_image1">Upload Image
1</label><br/>
<%= file_field :image1, :uploaded_data %></p>
<p><label for="equipment_image2">Upload Image
2</label><br/>
<%= file_field :image2, :uploaded_data %></p>
<p><label for="equipment_image3">Upload Image
3</label><br/>
<%= file_field :image3, :uploaded_data %></p>
<p><label for="equipment_image4">Upload Image
4</label><br/>
<%= file_field :image4, :uploaded_data %></p>
<p><label
for="equipment_status">Status</label><br/>
<%= select :equipment, :status, [''For Sale'',
''Sold''] %></p>
<%= 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,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---