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).
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.