For some reason I can’t figure out why the nested elements are not appearing in this edit form.
class Book < ActiveRecord::Base
has_many :pages
accepts_nested_attributes_for :pages
end
class Page < ActiveRecord::Base
belongs_to :book
end
Heres the form
<%= form_for(:book) do |f| %>
<p><%= f.text_field(:title) %></p>
<%= f.fields_for :pages do |page| %>
<p><%= page.text_field(:page_no) %></p>
<% end %>
<% end %>
Controller
def edit
@book = Book.find(params[:id])
end
It displays the title of the book but nothing appears when it goes to list the page_nos. Also I tried calling :pages and it returns an array of pages so I don’t see why the form isn’t being built.
Am I overlooking something in the model I need to change?
Try with
instead of