I can't display the locations that belogns to the user using nested forms.
I want to create the user and save the address, city, state, etc in location model and the name, username, email in the user model.
I have no errors on the console. But the fields (select or dropdowns, text_fields, etc) are not showing up. The database has records.
This is my user.rb model:
class User < ActiveRecord::Base
has_many :locations
accepts_nested_attributes_for :locations
end
This is my location.rb model:
class Location < ActiveRecord::Base
belongs_to :user
end
This is my user form:
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<%= form_for(["admin", @user]) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :username %><br>
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :email %><br>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br>
<%= f.text_field :password %>
</div>
<!-- Here is the nested form -->
<%= f.fields_for :locations do |location| %>
<%= location.label :country %>
<%= location.select :country%>
<%= location.label :state %>
<%= location.text_field :state%>
<% end %>
<div class="actions form-group">
<%= f.submit class: 'form-control' %>
</div>
<% end %>