1
我正在开发一个Web应用程序,它必须在主页上显示产品列表。 为此,我有一个ProductsController的:如何为使用HAML的视图创建助手?
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代码的情况下做到这一点。
有什么想法,我该如何做到这一点?
我不认为你可以不丑陋。为什么不使用偏分量? –