2012-04-01 15 views
5

Bir şekilde active_admin order show page, hiçbir şansın order için line items görüntülemek çalışıyorum .. Burada active_admin başka bir öğe ait öğelerin listesini

modelleri arasında ilişkiler gösterilecek order.rb

class Order < ActiveRecord::Base 
    has_many :line_items, :dependent => :destroy 
    # ... 
    validates :name, :address, :email, :presence => true 
    validates :pay_type, :inclusion => PAYMENT_TYPES 
end 

line_item.rb

class LineItem < ActiveRecord::Base 
    belongs_to :order 
    belongs_to :product 
    belongs_to :cart 

    def total_price 
    product.price * quantity 
    end 

end 

active_admin order.rb

ActiveAdmin.register Order do 

    show do 
    attributes_table :name, :email, :address, :pay_type, :created_at, :updated_at 
    end 
end 

active_admin Gösteri siparişi tıkladığımda

class LineItem < ActiveRecord::Base 
    belongs_to :order 
    belongs_to :product 
    belongs_to :cart 

    def total_price 
    product.price * quantity 
    end 

end 

, bu uygulamanın bu sipariş için ürün .. göstermesi gerekir line_item.rb dosyayı gösterme

<%= render @order.line_items %> 

_line_items.html.erb

<!-- START_HIGHLIGHT --> 
<% if line_item == @current_item %> 
    <tr id="current_item"> 
    <% else %> 
<tr> 
<% end %> 
<!-- END_HIGHLIGHT --> 
    <td><%= line_item.quantity %>&times;</td> 
    <td><%= line_item.product.title %></td> 
    <td class="item_price"><%= number_to_currency(line_item.total_price) %></td> 
</tr> 

ve ürün sayfasında, ancak Active_Admin ben o iş yapmak nasıl bilmiyorum .. yardım edin. Zaman ayırdığın için teşekkürler. bruno077 için

çözüldü

teşekkürler Sonunda şimdilik ürünün kimliğini aldı ActiveAdmin

show do |order| 

    panel "Customer details" do 
    attributes_table_for order, :first_name, :last_name, :card_type, :created_at, :ip_address 
    end 

    panel("Products for this order") do 
    table_for(order.line_items) do 
     column "Product" do |item| 
     item.product.title 
     end 
     column "Price" do |item| 
     item.product.price 
     end 
     column "Quantity" do |item| 
     item.quantity 
     end 
    end 
    end 
end 

sipariş show_page içinde line_items başardı, ancak burada uzakta değil istediğimi almak için. Şerefe!

cevap

10

Böyle bir şey işe yarayabilecek:

ActiveAdmin.register Order do 
    show do |order| 
    div do  
     panel("Items") do 
     table_for(order.line_items) do 
      column :quantity 
      column "Title" do |i| 
      i.product.title 
      end 
      column "Price" do |i| 
      number_to_current(i.total_price) 
      end 
     end 
     end 
    end 
    end 
end 

size bir ipucu verebilir Başka alakasız bir örnek:

# => Show 
    show :title => :date do |gallery| 
    panel "Galería" do 
     attributes_table_for gallery, :name, :description, :date 
    end 

    panel "Fotos" do 
     table_for(gallery.gallery_files) do 
     column "Título", :title 
     column "Fecha", :date 
     column "Foto" do |image| 
      image_tag image.file.url(:thumb).to_s 
     end 
     end 
    end 

    end 
+0

yazım hatası, beklenmedik '{', bekliyor kend sütun 'title' {ürünü .title} Bu tür 4 hata var, her biri için 1 tane "{" lütfen ona bir göz atabilir misiniz? En azından denemek için çok teşekkür ederim. – rmagnum2002

+0

sütunları oluşturur, bu şeyi sadece ben +1 oyu veririm, bu çok yardımcı oldu, ama gerçekten bu ilişkileri Active Admin'de çalışmak için almam gerekiyor. – rmagnum2002

+0

Belki de {} gösterim ActiveAdmin ile çalışmayabilir, cevabı güncelleyeceğim. – bruno077

İlgili konular