gpt4 book ai didi

ruby-on-rails - 我们如何在事件管理中为索引面板创建部分

转载 作者:行者123 更新时间:2023-12-05 00:01:27 24 4
gpt4 key购买 nike

我想创建一个部分来为 DRY 的不同命名空间在索引面板中呈现一些数据

我目前正在写作

 index do
render 'index', user: :user
end
//_index.html.arb
column :id
column 'Customer Name', :name
column :mobile
column :recipient_number
column :cash_in_hand do |customer|
number_to_currency(customer.cash_in_hand, unit: "\u20B9", precision: 2)
end
column "Due Balance" do |customer|
number_to_currency(customer.due_balance, unit: "\u20B9", precision: 2)
end
actions

最佳答案

您可以创建一个部分来完全像这样呈现该数据

# app/admin/some_class.rb
index do
render 'admin/index', context: self
end

您可能希望在这些类型的部分 View 中创建一个名为“admin”的文件夹......
# app/views/admin/_index.html.erb
<% context.instance_eval do
column :id
column 'Customer Name', :name
column :mobile
column :recipient_number
column :cash_in_hand do |customer|
number_to_currency(customer.cash_in_hand, unit: "\u20B9", precision: 2)
end
column "Due Balance" do |customer|
number_to_currency(customer.due_balance, unit: "\u20B9", precision: 2)
end
actions
end %>

I can confirm this works with .erb extention file and .haml but no guaranteeing others

关于ruby-on-rails - 我们如何在事件管理中为索引面板创建部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34541669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com