Reputation: 41
I'm trying to create a new section in a nested page object. I defined the page object but I got this error undefined method `page' for #. Rails is complaining for the code below.
<td><%= f.object.page.name %></td>
sections.rb file code
belongs_to :pages, optional: true
validates :page_id, presence: true
Upvotes: 0
Views: 80
Reputation: 5363
belongs_to :pages
should be belongs_to :page
Also in your view, make sure that you're checking if it's nil before rendering it. f.object.page.name unless f.object.page.nil?
Upvotes: 2