我在电子商务网站上工作并在我的索引页面中出错,但我找不到coprend的位置。 有人可以帮我吗? 谢谢!
%h1 Products
- if @products.present?
%ul
- @products.each do |product|
%li= link_to product.name, product_path(product)
—
- if product.stock.zero?
Out of stock!
- else
= link_to 'Buy', checkout_product_path
- else
No products
%a{href: new_product_path} Add product
my products_controlller.rb
class ProductsController < ApplicationController
before_action :authenticate_user!, only: [:checkout, :buy]
def index
@product = Product.all
end
def show
@product = Product.find(params[:id])
end...
...
private
def product_params
params.require(:product).permit(:name, :price, :image_url, :stock)
end
end
答案 0 :(得分:-1)
试试这个:
%h1 Products
- if @products.present?
%ul
- @products.each do |product|
%li
= link_to product.name, product_path(product)
—
- if product.stock.zero?
Out of stock!
- else
= link_to 'Buy', checkout_product_path
- else
No products
%a{href: new_product_path} Add product