I have a create product page that allows users to add multiple images to a product. So naturally I have a number of image upload fields however, when the product is created it will only take ONE PHOTO and add it to the database. Not the others. I am making some simple mistake but I have no idea what it is.
Thanks for the help !
new product form (haml)
%h1
create item
= form_for @product,:url => products_path, :html => { :multipart => true } do |f|
%p
= f.label :name
= f.text_field :name
%p
= f.label :description
= f.text_field :description
%p
= fields_for :photo, :html => {:multipart => true} do |fp|
=fp.file_field :image
%p
= fields_for :photo, :html => {:multipart => true} do |fp|
=fp.file_field :image
%p.button
= f.submit
products controller
def new
@product = Product.new
@photo = Photo.new
end
def create
@product = current_user.products.build(params[:product])
@photo = current_user.photos.new(params[:photo])
if @product.valid? && @photo.valid?
@product.save
@photo.product_id = @product.id
@photo.save
render "show", :notice => "Sale created!"
else
render "new", :notice => "Somehting went wrong!"
end
end