I have the following ActiveAdmin form:
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
When I use this form in the edit view, the select drop-down automatically defaults to the present value. However in production the drop-down is for some reason defaulting to the blank value at the top (why is that blank value there anyway?).
EDIT
The problem seems to be that ActiveAdmin doesn't understand the association and is unable to select associated object by default. I need to figure out how to code the f.input
for the association. The form is for a Timesheet. A Timesheet has_many
JobsAssignedWorkers and each JobsAssignedWorker has a Worker.
If you want to include blank value:
f.input :jobs_assigned_worker,
label: 'Worker',
as: :select,
collection: -> { Worker.pluck(:name) },
include_blank: true
If you don't want to include blank value:
f.input :jobs_assigned_worker,
label: 'Worker',
as: :select,
collection: -> { Worker.pluck(:name) },
include_blank: false
If you want to have blank value, but don't want to allow it as an option:
f.input :jobs_assigned_worker,
label: 'Worker',
as: :select,
collection: -> { Worker.pluck(:name) },
include_blank: true,
allow_blank: false
Try to set 'include_blank' option.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With