undefined method 'id' for nil: NilClass

0

I'm a beginner in ruby, and I had this error ...

 def new
    @section = Section.new({:page_id => @page.id, :name => "Default"})
    @pages = @page.subject.pages.sorted
    @section_count = Section.count + 1
  end

It says the problem is on line two, can someone help me?

    
asked by anonymous 28.03.2017 / 10:46

1 answer

1

This is darned to be a new method in a Rails application controller where @page would be initializing somewhere out of the method, probably in a before_action . If you do not initialize @page with something, it is automatically initialized with nil and will give that error there. Look at your controller where it has some reference to @page that you will find (or not, if it is not there) your problem.

    
28.03.2017 / 23:41