2

Edit form submit POST request instead of PUT request even though _method hidden field is available inside the form like shown below

<form id="edw_special_debts_child_form" class="will-form" action="/equitable_distribution_will/update-special-debts-child" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="_method" value="put">
<input type="hidden" name="authenticity_token" value="xxxxxxxx">

There is no JS error that appears in the console.

Rails error:

No route matches [POST] "/update-special-debts-child"

the form generated using this code

<%= form_tag(will_form_url, :id => "edw_special_debts_child_form", method: @form_method, class: "will-form") do %>

        <% if have_sons?(@calculator) || have_daughters?(@calculator) %>
            <%= render partial: "shared/will_question_repeater_block", locals: {q: @children_compensate_question} %>
        <% end %>
        <div class="btn-nav space-bet">
            <% if (have_wife?(@calculator) || session[:will_spouse_non_muslim] == 'true') && current_user.gender == 'male' %>
                <%= link_to "Previous", equitable_distribution_will_special_debts_wife_path, class: "text-center btn-gold gotham" %>
            <% else %>
                <%= link_to "Previous", equitable_distribution_will_special_debts_lp_path, class: "text-center btn-gold gotham" %>
            <% end %> 
            <button type="submit" class="text-center btn-gold gotham">Save & Continue</button>
        </div>

    <% end %>

and here is the helper

def will_form_url
    form_url = "#{action_name}"
    @form_method = ""

    if $tables[action_name.to_sym].where(will_id: session[:will_id]).present?
        form_url = form_url.insert(0, 'equitable_distribution_will_update_')
        @form_method = "put"
    else
        form_url = form_url.insert(0, 'equitable_distribution_will_create_')
        @form_method = "post"
    end
    form_url = form_url.insert(-1, '_path')
    send(form_url)
end

the tricky part in my form, I'm duplicating the fields via JS and appending '[]' at the end of each form element to get an array of values.

If I add just a single row, then the edit form will work fine, but when I add multiple rows, it gets submitted over POST instead of PUT

What could be the issue?

FDI
  • 771
  • 1
  • 9
  • 25

0 Answers0