Note that there are some explanatory texts on larger screens.

plurals
  1. POactive_admin - display a list of items that belongs to another item
    primarykey
    data
    text
    <p>I am trying to display somehow the <code>line items</code> for the <code>order</code> in the active_admin <code>order show page</code>, no luck..</p> <p>here are the relations between models:</p> <p><strong>order.rb</strong></p> <pre><code>class Order &lt; ActiveRecord::Base has_many :line_items, :dependent =&gt; :destroy # ... validates :name, :address, :email, :presence =&gt; true validates :pay_type, :inclusion =&gt; PAYMENT_TYPES end </code></pre> <p><strong>line_item.rb</strong></p> <pre><code>class LineItem &lt; ActiveRecord::Base belongs_to :order belongs_to :product belongs_to :cart def total_price product.price * quantity end end </code></pre> <p><strong>active_admin order.rb</strong></p> <pre><code>ActiveAdmin.register Order do show do attributes_table :name, :email, :address, :pay_type, :created_at, :updated_at end end </code></pre> <p><strong>active_admin line_item.rb</strong></p> <pre><code>class LineItem &lt; ActiveRecord::Base belongs_to :order belongs_to :product belongs_to :cart def total_price product.price * quantity end end </code></pre> <p>when I click show order, it must display the items for this order.. In application's show file I did it with </p> <pre><code>&lt;%= render @order.line_items %&gt; </code></pre> <p><strong>_line_items.html.erb</strong></p> <pre><code>&lt;!-- START_HIGHLIGHT --&gt; &lt;% if line_item == @current_item %&gt; &lt;tr id="current_item"&gt; &lt;% else %&gt; &lt;tr&gt; &lt;% end %&gt; &lt;!-- END_HIGHLIGHT --&gt; &lt;td&gt;&lt;%= line_item.quantity %&gt;&amp;times;&lt;/td&gt; &lt;td&gt;&lt;%= line_item.product.title %&gt;&lt;/td&gt; &lt;td class="item_price"&gt;&lt;%= number_to_currency(line_item.total_price) %&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>and the items are in the page, but in Active_Admin I don't know how to make it work.. Please help. Thank you for your time.</p> <p><strong>Solved</strong></p> <p>Thanks to bruno077 I managed to finally get the line_items in the order show_page in ActiveAdmin</p> <pre><code> 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 </code></pre> <p>I got the ID of the product for now, but it's not far from here to get what I want. Cheers!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload