小编Waq*_*wan的帖子

错误:验证失败:图像可成像必须存在,rails-5.0,paperclip-5

当我试图提交表单时,发生以下错误:Validation failed: Images imageable must exist并呈现相同的new.html.erb视图.

如果我评论了file fieldnew.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)

image-uploading paperclip ruby-on-rails-5

14
推荐指数
1
解决办法
2430
查看次数