Black Dynamite
Black Dynamite

Reputation: 4147

Submit button not working on nested form

I am using RoR and I have 2 objects, Warehouse and StateCity. The Warehouse object belongs_to the StateCity object. In my form, the submit button for creating a new Warehouse will not submit when I have the following StateCity code in my _form.erb.html for the Warehouse.

<%= form_for (@warehouse) do |f| %> 
...
<%= form_for (@state_city) do |s| %>
    <div class="field">
      <%= s.label :city %><br />
      <%= s.text_field :city %>
    </div>
    <div class="field">
      <%= s.label "State" %><br />
      <%= select_tag("state", options_for_select(us_states ,@state_city.state )) %>
    </div>
<% end %>
<% end %>

Does anyone know where I am going wrong ? My main goal is to have the user select a State and City, then I take that information and try to find a matching model in the db. Should a model not be found, I create one and set the StateCity property on the new Warehouse. I don't want to build a new StateCity everytime a Warehouse is saved and have redundant rows in the db.

Any help is greatly appreciated.

Upvotes: 1

Views: 897

Answers (1)

Mart&#237;n Peverelli
Mart&#237;n Peverelli

Reputation: 328

Please see this answer: https://stackoverflow.com/a/379622/1913769

You cannot nest Forms on HTML.

Upvotes: 2

Related Questions