当我试图提交表单时,发生以下错误:Validation failed: Images imageable must exist并呈现相同的new.html.erb视图.
如果我评论了file field在new.html.erb.产品正在成功创建.
ProductsController的:
def new
@product = Product.new
end
def create
@product = Product.create!(product_params)
if @product.save
redirect_to products_path, notice: "Product Created Successfully"
else
render "new"
end
end
def product_params
params.require(:product).permit(:name, :quantity, :price, images_attributes: [:id, :photo, :_destroy])
end
Run Code Online (Sandbox Code Playgroud)
new.html.erb:
<%= nested_form_for @product, html: { multipart: true } do |f|%>
<h2>New</h2>
<P> <%= f.label :name %> <%= f.text_field :name %> </P>
<P> <%= f.label :quantity %> <%= f.text_field …Run Code Online (Sandbox Code Playgroud)