# Acts\_as\_attachment Editing Images

**URL:** <https://www.ruby-forum.com/t/acts-as-attachment-editing-images/89462>\
**Category:** Rails\
**Created:** [March 20, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-editing-images/89462 "2007-03-20T17:31:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://www.ruby-forum.com/u/Chad)\
**Post date:** [March 20, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-editing-images/89462/1 "2007-03-20T17:31:57Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![Chad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://www.ruby-forum.com/u/Chad)\
**Post date:** [March 20, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-editing-images/89462/2 "2007-03-20T18:12:20Z")

</div>

I am also having the same problem. Apparently there is no method for  
updating an attachment record. How can I get around this? Here is what  
I have:

==VIEW==

\<%= file\_field “image”, “uploaded\_data” %\>

==CONTROLLER==

unless params[:image][:uploaded\_data].blank?  
image = @person.images(0)  
image.update\_attributes(params[:image])  
end

==ERROR==

NoMethodError in PeopleController#edit  
undefined method `update\_attributes’ for Image:Class

---

<div class="post-metadata">

**Author:** ![Chad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://www.ruby-forum.com/u/Chad)\
**Post date:** [March 20, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-editing-images/89462/3 "2007-03-20T20:19:32Z")

</div>

I have been looking at Mephisto and they use acts\_as\_attachment to  
manage assets. It also has the ability to edit any files you upload  
and write over them. Does anyone know how this is done?

On Mar 20, 11:12 am, Taylor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
