Zekarias Zico
Zekarias Zico

Reputation: 41

undefined method `page' for

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

Answers (1)

Josh Brody
Josh Brody

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

Related Questions