Próbuję wyświetlić jakoś line items
dla order
w active_admin order show page
, bez powodzenia ..active_admin - wyświetla listę elementów, które należy do innego elementu
Oto relacje między modelami:
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
po kliknięciu pokazu zamówienie, musi wyświetlić elementy dla tego celu .. Przy stosowaniu na pokaż plik Zrobiłem to z
<%= 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>
i przedmioty są na stronie, ale w Active_Admin nie wiem jak zrobić to działa .. Proszę o pomoc. Dziękuję za Twój czas.
rozwiązany
Dzięki bruno077 udało mi się w końcu dostać line_items w show_page zamówienia w 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
mam identyfikator produktu do teraz, ale to nie jest daleko stąd dostać to, czego chcę. Twoje zdrowie!
błąd składni, nieoczekiwany '{', oczekując Kend kolumnie 'Nazwa' {produkt .title} są 4 tego rodzaju błędy, po 1 dla każdego "{" czy mógłbyś na to spojrzeć? Dziękuję bardzo za przynajmniej próbowanie. – rmagnum2002
tworzy kolumny, tym rzeczom tylko, że głosuję +1, to było naprawdę pomocne, ale naprawdę muszę uzyskać te relacje do pracy w Active Admin. – rmagnum2002
Myślę, że może notacja {} może nie działać z ActiveAdminem, zaktualizuję odpowiedź. – bruno077