After trying to save a set of images with dropzone without iteration. i switch to iterating the images and try to save on the loop. but rails spitting
ActiveRecord::StatementInvalid at /products =========================================== > SQLite3::ConstraintException: NOT NULL constraint failed: images.product_id: INSERT INTO "images" ("created_at", "ifoto", "product_data_id", "product_id", "updated_at") VALUES (?, ?, ?, ?, ?) app/controllers/products_controller.rb, line 214 ------------------------------------------------
ruby 209 210 if params[:images] && params[:images][:ifoto] 211 params[:images][:ifoto].values.each do |ifoto| 212 213 @image.ifoto = ifoto > 214 @image.save 215 216 217 end 218 render :nothing => true 219
App backtrace ------------- - app/controllers/products_controller.rb:214:inblock (3 levels) in create' - app/controllers/products_controller.rb:211:in
block (2 levels) in create' - app/controllers/products_controller.rb:137:in `create' Full backtrace --
here is the dropzone code
format.json do
@product = current_vitrine.products.build(params[:product])
@image = @product.images.build(params[:images])
if params[:images] && params[:images][:ifoto]
params[:images][:ifoto].values.each do |ifoto|
@image.ifoto = ifoto
@image.save
end
render :nothing => true
end
end
someone have a hint to this kind of problem?
Aucun commentaire:
Enregistrer un commentaire