我有一個表格要求用戶根據他們在公司內的職位來評估一個人。但是,用戶需要選擇評估處於他們當前不佔據的不同位置的人員。雖然我有一個允許他們選擇其他職位的下拉列表,但我的表單目前不會更新用戶根據新職位評估的問題。我將如何納入這一點?如何根據Rails中的下拉列表選擇來修改表單?
reports_controller.rb
def new
# Find or create a new report
@report = Report.unscoped.where(employee_id: @employee.id, author_id: current_user.id).first_or_initialize do |record|
# Build new record if it didn't already exist
end
# Add skills for evaluations based on the employee's position
@skills.includes(:positions).where(positions: { id: @employee.position.id }).each do |skill|
@report.evaluations << Evaluation.new(skill_id: skill.id) unless @report.evaluations.any? { |e| e.skill == skill}
end
end
_form.html.erb
<%= simple_form_for([@employee, @report] do |f| %>
<%= f.error_notification %>
<!-- Drop Down list where user determines which position they wish to evaluate the employee for... -->
<%= f.association :position, label: "Position Evaluated", selected: @employee.position.id %>
<!-- Skills for the user to evaluate the employee, should change depending on the value selected from the drop down box. -->
<%= f.nested_fields_for :evaluations do |fn| %>
<%= fn.input :skill_id, as: :hidden, input_html: {value: fn.object.skill.id} %>
<%= fn.object.skill.name %>
<%= fn.association :grade %>
<%= fn.input :explanation, input_html: { rows: 3 } %>
<% end %>
<% f.button :submit, "Update Report", class: "btn btn-primary" %>
<% end %>