Forum: Ruby on Rails acts_as_attachment Editing Images

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chad (Guest)
on 2007-03-20 18:31
(Received via mailing list)
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,
Taylor S. (Guest)
on 2007-03-20 19:12
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
Chad (Guest)
on 2007-03-20 21:19
(Received via mailing list)
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>
This topic is locked and can not be replied to.