我正在開發電子商務應用程序。店鋪經理可以通過活動管理員上傳產品。當產品上傳時,它被分配到category
和active admin
面板中的label
,該功能很好地解決了問題。是否可以通過ROR App中的活動管理面板在視圖中重新排列產品訂單
最近product
在每個category
通過下面的代碼在views/pages/index.html.erb
上顯示爲類別正面圖像,它的作用有點像charm。
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 %>
當客戶點擊客戶被帶到category page
pages/categories/show.html.erb
那裏的客戶可以通過在所選類別的所有產品瀏覽在views/pages/index.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),今天他上傳了一個產品(productB),他希望顯示在productA旁邊。但在這些產品之間是其他產品的100。
所以我的問題的背景是:如何是商店經理能夠在active admin
面板重新安排的產品,使產品A和產品B在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
謝謝我明天將會看到它 – DaudiHell
它似乎工作:) – DaudiHell