我想在我的主页上添加特色产品和最新产品,我正在复制 spree_fancy gem 方法并使用以下迁移添加分类单元,但不在侧栏中显示标签,但我不确定这部分迁移正在做什么 -
products = Spree::Product.all
if products[6]
products[0..6].each do |product|
product.taxons << slider
end
end
if products[16]
products[4..16].each do |product|
product.taxons << featured
end
products[0..12].each do |product|
product.taxons << latest
end
这是完整的迁移
class AddSliderTaxonsAndApplyThem < ActiveRecord::Migration
def up
tags = Spree::Taxonomy.create(:name => 'Tags')
slider = Spree::Taxon.create({:taxonomy_id => tags.id, :name => 'Slider'})
featured = Spree::Taxon.create({:taxonomy_id => tags.id, :name => 'Featured'})
latest = Spree::Taxon.create({:taxonomy_id => tags.id, :name => 'Latest'})
products = Spree::Product.all
if products[6]
products[0..6].each do |product|
product.taxons << slider
end
end
if products[16]
products[4..16].each do |product|
product.taxons << featured
end
products[0..12].each do |product|
product.taxons << latest
end
end
end
def down
Spree::Taxonomy.where(:name => 'Tags').first.destroy()
end
end