我在开发电子商务应用。商店经理可以通过主动管理员上传产品。上传产品后,会将其分配到category
面板中的label
和active admin
,这样可以很好地解决问题。
每个product
中的最新category
在views/pages/index.html.erb
上通过以下代码显示为类别正面图像,它就像魅力一样。
views/pages/index.html.erb
<% @products.each_slice(3) do |products_group| %>
<div class="row">
<% products_group.each do |category, products| %>
<% products.each_with_index do |product, index| %>
<% if index == 0 %>
<div class="col-lg-4 col-sm-6 col-xs-12 center-block " >
<%= link_to category_path (category), { :method => 'GET' } do %>
<%= image_tag product.image.url(:medium), class: "img-responsive" %>
<% end %>
<div class="caption">
<p class="category-name" ><%= product.category.name %></p>
</div>
<% end %>
<% end %>
</div>
<% end %>
</div>
<% end %>
当客户点击views/pages/index.html.erb
中的图片链接时,客户将被带到category page
pages/categories/show.html.erb
,客户可以浏览所选类别中的所有产品。
pages/categories/show.html.erb
<div class="container-fluid">
<div class="row category_top">
<% @products.each do |product| %>
<div class="col-lg-3 col-sm-6 col-xs-12 center-block " >
<%= link_to product_path (product) do %>
<%= image_tag product.image.url(:medium), class: "img-responsive" %>
<% end %>
<div class="product_description">
<h5><%= link_to product.title, product %></h5>
<p><%= social_share_button_tag(product.title) %></p>
</div>
</div>
<% end %>
</div>
</div>
问题在于pages/categories/show.html.erb
商店经理希望某些产品能够彼此相邻。
例如: 4天前他上传了一个产品(productA),今天他上传了一个他希望在productA旁边显示的产品(productB)。但在这些产品之间是100种其他产品。
因此我的问题的背景是:商店经理如何能够在active admin
面板中重新安排产品,以便productA和productB在pages/categories/show.html.erb
中彼此相邻视图?我甚至可能吗?
P.S。这是我第一次使用主动管理员
以下是app/admin/admin_user.rb
ActiveAdmin.register AdminUser do
permit_params :email, :password, :password_confirmation
index do
selectable_column
id_column
column :email
column :current_sign_in_at
column :sign_in_count
column :created_at
actions
end
filter :email
filter :current_sign_in_at
filter :sign_in_count
filter :created_at
form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end
这是categories_controller.rb
class CategoriesController < ApplicationController
before_action :set_category, only: [:show, :edit, :update, :destroy]
def index
@categories = Category.all
end
def show
@products = @category.products
@images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"]
@random_no = rand(5)
@random_image = @images[@random_no]
end
private
# Use callbacks to share common setup or constraints between actions.
def set_category
@category = Category.includes(:products).find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def category_params
params.require(:category).permit(:name, :slug)
end
end