[英]Create a custom string filter in ActiveAdmin that defaults to Contains and doesn't show a string filter choice drop down - Formtastic & Ransack
[英]ActiveAdmin :select drop-down defaults to current value in development but defaults to blank in production
我有以下 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
当我在编辑视图中使用此表单时,select 下拉菜单自动默认为当前值。 但是在生产中,由于某种原因,下拉菜单默认为顶部的空白值(为什么那个空白值仍然存在?)。
编辑
问题似乎是 ActiveAdmin 不理解该关联,并且默认情况下无法将 select 关联 object 。 我需要弄清楚如何为关联编写f.input
代码。 该表格用于时间表。 Timesheet has_many
JobsAssignedWorkers 并且每个 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
尝试设置 'include_blank' 选项。
form do |f|
f.inputs "Timesheet Details" do
f.input :jobs_assigned_worker, :label => "Worker", as: :select, collection: Worker.all, include_blank: false
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
为避免保留空白值,只需在您的 select 中添加此选项:
include_hidden: false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.