0

I was looking at the question below, which has a good answer for what I will ask, but I have a doubt. I cannot comment yet so that is why I am making another post.

How to submit multiple, duplicate forms from same page in Rails - preferably with one button

This is my view for the form

new.html.erb

<h1 class="page-title">Nuevo Precio</h1>
<hr class="title-division">

<div class="alta-form-container">
<%= form_tag "/precios" do %>
    <% 2.times do %>
        <%= render 'form', precio: @precio %>
    <% end %>
    <%= submit_tag "Submit", class: "btn btn-success" %>
<% end %>

<%= link_to 'Lista Precios Cliente', client_precios_path %> <br><%= link_to 'Ver', [@client, @precio] %> <br>
</div>

and my _form.html.erb

<div class="field">
  <%= label_tag :precio, "Precio" %>
  <%= text_field_tag "precios[][precio]" %>
</div>

<div class="field">
  <%= text_field_tag "precios[][cant_acomodato]" %>
</div>

<div class="field">
  <%= hidden_field_tag "precios[][client_id]" %>
</div>

When I submit the form I get an error that says

'No route matches [POST] "/precios"'

which I'm guessing is because on my new.html.erb I wrote form_tag "/precios" do

Any thoughts on what I should change or edit? thanks in advance

1 Answers1

0

actually you have only one form here, because _form.html.erb will generate only inputs, that according to form below

<%= form_tag "/precios" do %>

that will generate

form action="/precios" method="post">

if you want leave it like that, you should add to your config/routes.rb

post '/precios', to: 'controller_name#method_name', as: :controller_name_method_name

your situation:

    post '/precios', to: 'PreciosController#create', as: :precios_create

also check this documentation

invaq
  • 41
  • 2
  • So I added that route to routes.rb and I get this error: 'PreciosController' is not a supported controller name. This can lead to potential routing problems. See https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use – FknCharlie May 18 '21 at 17:18
  • because RAILS thinks this name breaks the convention of controller(PrecioS - like plural, should be singular) naming check this https://guides.rubyonrails.org/action_controller_overview.html#controller-naming-convention @FknCharlie – invaq May 27 '21 at 14:13