非法嵌套:内容不能与%h1在同一行上给出并嵌套在其中

时间:2015-10-23 16:18:55

标签: ruby-on-rails ruby haml

我在电子商务网站上工作并在我的索引页面中出错,但我找不到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

1 个答案:

答案 0 :(得分:-1)

试试这个:

%h1 Products
  - if @products.present?
    %ul
      - @products.each do |product|
        %li
          = link_to product.name, product_path(product)
          &mdash;
          - if product.stock.zero?
            Out of stock!
          - else
            = link_to 'Buy', checkout_product_path
  - else
    No products

  %a{href: new_product_path} Add product