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
添加回答
舉報