Search code examples
ruby-on-railssimple-form

Rails Simple form submit not sending value over to controller


I have a problem figuring out why is simple_form not sending over the text box value. The params are missing the raw_score

Heres my controller def create student_station_result = StudentStationResult.new

student = Student.find_by_register_no(params[:result_entry][:register_no])
student_sezzion_id = StudentSezzion.joins(:student_group).where(student_groups: { sezzion_id: params[:sezzion_id] }, student_id: student.id).pluck(:id).first

# TODO: Replaced after the NAPFA result calculation is done
student_station_result.station_point = 1
student_station_result.student_sezzion_id = student_sezzion_id
student_station_result.raw_score = params[:result_entry][:raw_score]
student_station_result.sezzion_station_id = params[:sezzion_station_id]
student_station_result.save!
end

Heres my html

= simple_form_for :result_entry, url: sezzion_sezzion_station_student_group_student_station_results_path do |f|
- @students.each do |student|
  - student_station_result = get_student_station_result(@station_id, student.id)
  .same-category
    .collapsible-container
        .collapsible-head
          .wrap
            .index
              h1 = student.register_no
            .name
              h3 = student.name
            .grade
              h1 = student_station_result[:performance_grade] if student_station_result.present?
              h5 = "x#{student_station_result[:raw_score]}" if student_station_result.present?
            .arrow
              #arrow-toggle =image_tag('arrow.svg', class: ['arrow-up', 'size'])

          .collapsible-body
            .grade-wrap
              .station-grade A: < 12.01s
              .station-grade B: 12.01 - 13.11
              .station-grade C: 13.11 - 14.11
              .station-grade D: 14.21 - 15.11
              .station-grade E: 15.31 - 16.51

            .score-input
              = f.input :raw_score, label: false, wrapper: false, input_html: { class: ['result-entry-textbox'], value: (student_station_result[:raw_score] if student_station_result.present?)}

              = f.input :register_no, as: :hidden, input_html: { value: student.register_no }
              = f.submit 'SAVE', class: ['result-entry-save', 'result-save-button']

Help will be appreciated. Thank you!


Solution

  • I have found the solution and it is quite stupid actually. Its because

    = simple_form_for :result_entry, url: sezzion_sezzion_station_student_group_student_station_results_path do |f|
    

    is at the top of the page. Thus only letting the last field get submitted. It should be placed inside the simple_form block.