After adding an attribute to params
images_attributes: [:file] I attach the file and when I create a new product, an error occurs
- Images product must exist What could be the snag?
Controller:
def new @product = Product.new @product.images.build end def create @product = Product.new(product_params) @product.user = current_user if @product.save redirect_to @product else render 'new' end end private def product_params params.require(:product).permit(:name, :description, images_attributes: [:file]) end new.html.slim
= f.fields_for :images do |i| = i.file_field :file In the product accepts_nested_attributes_for :images, reject_if: :all_blank model accepts_nested_attributes_for :images, reject_if: :all_blank
In the model image mount_uploader :file, ImageUploader
Associations are all registered. I use carriewave and Rails 5