5
我試圖以某種方式顯示line items
在active_admin order show page
,沒有運氣的order
..active_admin - 顯示屬於另一個項目的項目列表
這裏是模型之間的關係:
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 line_item.rb
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product
belongs_to :cart
def total_price
product.price * quantity
end
end
當我點擊顯示訂單,它必須顯示此訂單的項目。在應用程序的顯示文件我用
<%= 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 %>×</td>
<td><%= line_item.product.title %></td>
<td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
</tr>
和項目在頁面上,但在Active_Admin我不知道如何使它工作..請幫助。感謝您的時間。
解決
感謝bruno077我設法最終得到的順序show_page的line_items在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
我的產品的ID現在,但它離這裏並不遠得到我想要的。乾杯!
語法錯誤,意外 '{',希望DMOZ目錄 列 '標題'{產品.title}這類錯誤有4個,每個「{」可以請你看一下嗎?至少非常感謝你的嘗試。 – rmagnum2002 2012-04-02 22:15:20
它創建的列,FOT這件事只有我投+1,這是reallly有益的,但我真的需要得到這個關係中主動管理工作。 – rmagnum2002 2012-04-02 22:26:13
我認爲{}符號可能不適用於ActiveAdmin,我會更新答案。 – bruno077 2012-04-02 23:02:21