После добавления в params атрибута
images_attributes: [:file]
Прикрепляю файл и при создании нового продукта выходит ошибка
- Images product must exist
В чем может быть загвоздка?
Контроллер:
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
В модели product accepts_nested_attributes_for :images, reject_if: :all_blank
В модели image mount_uploader :file, ImageUploader
Ассоциации все прописаны. Использую carriewave и Rails 5