Closed dcalixto closed 1 year ago
Very hard to debug this.
Try the following:
def images_params
params.require(:item).permit(images: {}) # <---- notice the curly bracked
end
https://apidock.com/rails/ActiveRecord/NestedAttributes/ClassMethods/accepts_nested_attributes_for
class Photo < ActiveRecord
has_many :images # is this what you are trying for?
accepts_nested_attributes_for :images # not sure if this is what you want.
end
@benkoshy thank you but the item has many photos! and the photo has image attachment
class Photo < ApplicationRecord
include ImageUploader::Attachment(:image)
belongs_to :item
validates :image, presence: true
end
and item
class Item < ApplicationRecord
has_many :photos, dependent: :destroy
accepts_nested_attributes_for :photos, allow_destroy: true, reject_if: proc { |attributes|
attributes['image'].blank? && attributes['id'].blank?
}
end
It is very hard to debug like this: but I would prefer something along the following linkes:
def item_params
params.require(:item).permit(photo_attributes: {}) # use the hash
end
It looks like you forgot to permit some parameters. This is not a bug in Shrine, because Shrine doesn't permit parameters for you.
after setup a simple multiple file upload between item and photos with nested routes
when i try to update the photos item, someone know why this?
Unpermitted parameter: :images. Context: { controller: PhotosController, action: create, request: #<ActionDispatch::Request:0x00007fc6d4ac9688>, params: {"item"=>{"images"=>{"0"=>#<ActionDispatch::Http::UploadedFile:0x00007fc6d4ae4690 @tempfile=#<Tempfile:/tmp/RackMultipart20230824-17259-174kltg.jpg>, @content_type="image/jpeg", @original_filename="caraguatatuba.jpg", @headers="Content-Disposition: form-data; name=\"item[images][0]\"; filename=\"caraguatatuba.jpg\"\r\nContent-Type: image/jpeg\r\n">, "1"=>#<ActionDispatch::Http::UploadedFile:0x00007fc6d4ae4618 @tempfile=#<Tempfile:/tmp/RackMultipart20230824-17259-1u4m5ml.jpg>, @content_type="image/jpeg", @original_filename="background2.jpg", @headers="Content-Disposition: form-data; name=\"item[images][1]\"; filename=\"background2.jpg\"\r\nContent-Type: image/jpeg\r\n">}}, "controller"=>"photos", "action"=>"create", "item_id"=>"130"} }
the dropzone edit form has a file field inside the dropzone fallback container
and the item and photos controller are using the standard methods
the dropzone