1 回答
TA贡献1798条经验 获得超7个赞
问题是在页面加载时,您的下拉列表中没有可供选择的选项;因此表单无法选择正确的值。您需要像这样更新您的控制器:
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to root_path }
format.json { render :new, status: :created, location: @product }
flash[:success] = "Product was successfully added."
else
@categories = Category.all.order(:name)
@subcategory = Subcategory.where(child_category_id: @product.child_category_id).order(:name)
@child_subcategory = ChildSubcategory.where(subcategory_id: @product.subcategory_id).order(:name)
format.html { render :new }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
添加回答
举报