rma*_*002 5 ruby-on-rails-3.1 activeadmin
我试图以某种方式显示line items了order在active_admin order show page,没有运气..
这里是模型之间的关系:
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
Run Code Online (Sandbox Code Playgroud)
line_item.rb
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product
belongs_to :cart
def total_price
product.price * quantity
end
end
Run Code Online (Sandbox Code Playgroud)
active_admin order.rb
ActiveAdmin.register Order do
show do
attributes_table :name, :email, :address, :pay_type, :created_at, :updated_at
end
end
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
当我点击显示顺序时,它必须显示此订单的项目..在应用程序的show文件中,我做了它
<%= render @order.line_items %>
Run Code Online (Sandbox Code Playgroud)
_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>
Run Code Online (Sandbox Code Playgroud)
和项目在页面中,但在Active_Admin我不知道如何使它工作..请帮助.感谢您的时间.
解决了
感谢bruno077,我终于在ActiveAdmin的show_page中获得了line_items
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
Run Code Online (Sandbox Code Playgroud)
我现在得到了该产品的ID,但距离这里得到我想要的东西并不远.干杯!
bru*_*077 10
像这样的东西可能会起作用:
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
Run Code Online (Sandbox Code Playgroud)
另一个不相关的例子可能会给你一个提示:
# => 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4947 次 |
| 最近记录: |