gpt4 book ai didi

ruby-on-rails - 事件管理员 :select drop-down defaults to current value in development but defaults to blank in production

转载 作者:数据小太阳 更新时间:2023-10-29 06:48:14 25 4
gpt4 key购买 nike

我有以下 ActiveAdmin 表单:

form do |f|
f.inputs "Timesheet Details" do
f.input :jobs_assigned_worker, :label => "Worker", as: :select, collection: Worker.all
f.input :worked_time_hours, :label => "Worked Time (Hours)"
f.input :worked_time_mins, :label => "Worked Time (Minutes)"
f.input :driving_time_hours, :label => "Driving Time (Hours)"
f.input :driving_time_mins, :label => "Driving Time (Minutes)"
f.input :spent_dollars, :label => "Extra Money Spent"
end
f.actions
end

当我在编辑 View 中使用此表单时,选择下拉列表自动默认为当前值。然而在生产中,由于某种原因,下拉列表默认为顶部的空白值(为什么那个空白值仍然存在?)。

编辑

问题似乎是 ActiveAdmin 不理解关联,默认情况下无法选择关联对象。我需要弄清楚如何为关联编写 f.input 代码。该表格用于时间表。时间表 有_many 个 JobsAssignedWorker,每个 JobsAssignedWorker 都有一个 Worker。

最佳答案

如果你想包含空白值:

f.input :jobs_assigned_worker,
label: 'Worker',
as: :select,
collection: -> { Worker.pluck(:name) },
include_blank: true

如果您不想包含空白值:

f.input :jobs_assigned_worker,
label: 'Worker',
as: :select,
collection: -> { Worker.pluck(:name) },
include_blank: false

如果你想有空值,但不想让它作为一个选项:

f.input :jobs_assigned_worker,
label: 'Worker',
as: :select,
collection: -> { Worker.pluck(:name) },
include_blank: true,
allow_blank: false

关于ruby-on-rails - 事件管理员 :select drop-down defaults to current value in development but defaults to blank in production,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25496196/

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