我正在开发一个必须在主页上显示产品列表的 Web 应用程序。为此,我有一个 ProductsController:
class ProductsController < ApplicationController
include ProductsHelper
def index
@products = Product.last(6).reverse
end
end
以及相应的视图 index.haml:
.main-container.col3-layout
.main
.col-wrapper
.col-main
.box.best-selling
%h3 Latest Products
%table{:border => "0", :cellspacing => "0"}
%tbody
- @products.each_slice(2) do |slice|
%tr
- slice.each do |product|
%td
%a{:href => product_path(:id => product.id)}
= product.title
%img.product-img{:alt => "", :src => product.image.path + product.image.filename, :width => "95"}/
.product-description
%p
%a{:href => "#"}
%p
See all from
%a{:href => category_path(:id => product.category.id)}
= product.category.label
=render "layouts/sidebar_left"
=render "layouts/sidebar_right"
为了提高效率,我想使用助手,但我不知道如果不在 products_helper.rb 文件中编写 HAML 代码,我怎么能做到这一点。
关于如何实现这一点有什么想法吗?