title: Rails 3.0/3.2: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
body: <p>I'm following the Kevin Skoglund tutorial Ruby on Rails 3 Essential Training, which was written for rails 3.0, though I am currently using 3.2. It uses the following method in the pages_controller with a before_filter to display only the pages which belong to the parent subject.</p>
  
  <p>The tutorial explicitly uses .find_by_id because if the result is nil it "will not return an error". However I get the "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" error when trying to view a page where @subject has been set to nil.</p>
  
  <pre><code>def find_subject
    if params[:subject_id]
      @subject = Subject.find_by_id(params[:subject_id])
    end
  end
  </code></pre>
  
  <p>The actual code that is causing the error is:</p>
  
  <pre><code>def list
    @pages = Page.order("pages.position ASC").where(:subject_id =&gt; @subject.id)
  end
  </code></pre>
  
  <p>Is this something that has changed since 3.0? If so, what would be the correct way to implement this functionality in 3.2?</p>