0
Im новой для Синатры, и у меня есть проблемы с DataMapper один-к-многимСинатра DataMapper один-ко-многим
db.rb
env = ENV["RACK_ENV"]
url = Dir.pwd + "/db/#{env}"
DataMapper.setup :default, "sqlite://#{url}.sqlite3"
class Order
include DataMapper::Resource
property :id, Serial
property :client, String
has n, :order_items
end
class OrderItem
include DataMapper::Resource
property :id, Serial
property :dish_id, Integer
belongs_to :order
end
DataMapper.finalize
DataMapper.auto_upgrade!
dishes.rb
DISHES = [
{ id: 1, name: "Mac and Cheese", category: "Pasta", price: 10 },
{ id: 2, name: "Steak", category: "Meat", price: 9 },
{ id: 3, name: "Fish and Chips", category: "Fish", price: 12 },
{ id: 4, name: "Tiramisu", category: "Dessert", price: 5 }
]
app.rb
get do
@orders = Order.all
@dishes = DISHES
haml %s(orders/index)
end
index.haml
%table.row
[email protected] do |order|
%tr
%td=order.client
%td
%ul
-order.order_items.each do |item|
%li
[email protected] { |dish| dish[:id] == item.dish_id }.first[:name]
эта линия:
[email protected] { |dish| dish[:id] == item.dish_id }.first[:name]
Не показывать любые блюда, которые клиент уже выбрал, что случилось?