-1

In my Rails app, I have two models: Product and Screenshot. Here is what my association between the two look like:

class Product < ActiveRecord::Base
  has_many :screenshots, :dependent => :destroy
end

class Screenshot < ActiveRecords::Base
  belongs_to :products
end

On my Edit Product form, I have made it so that I can view all of the screenshots belonging to the product. The screenshots can be deleted, but I want to make it so that, using AJAX, new screenshots can be added asynchronously. Please see the following link for a screenshot of the setup I've got on my form (I don't have 10 reputation, so I can't yet post images).

http://min.us/i/baP9RUNzOgGNa

I want to make it so that I can click on the "Add Screenshot" link, and it'll add the screenshot specified in the file field to the rendered screenshots below. I've been struggling with this for a couple of hours, and here's the closest I got:

<div class="control-group">
    <%= f.label :screenshots, :class => "control-label product-align-left" %>

    <div class="controls">
        <%= f.file_field "Add Screenshot", :name => "txtAddScreenshot" %>

        <%= link_to "Add Screenshot", add_screenshot_product_path(@product), :remote => true %>
    </div>
</div>

With this code, the add_screenshot action will be called, which is fine, but I won't have the file to be added available in the params. Is there any way I can get the file in the params? If not, how else should I approach this? I am using Paperclip for processing the screenshots.

Alexander
  • 3,959
  • 2
  • 31
  • 58
  • possible duplicate of [jQuery Ajax File Upload](http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload) – phoet Dec 15 '13 at 11:28
  • Hi phoet. I took a look at the SO question, but it did not seem related to my inquiry. I'm wondering if it's possible in any way to access the data from my file field when I want to add a screenshot. Rails seemed to ignore any nested forms, even though I've used a form within a form before, so I'm pretty stuck here. – Alexander Dec 16 '13 at 00:13

1 Answers1

0

Just to update everyone on this: HTML doesn't support forms within forms, so what I did was make a separate form for screenshots.

Alexander
  • 3,959
  • 2
  • 31
  • 58