title: Undefined method `foo' for nil:NilClass — throws error in view but works in rails console
body: <p>The following code keeps throwing a NoMethodError when I try to load. It was working earlier until I reset my database:</p>
  
  <pre><code>&lt;% pstate= Place.where(statename: @agency.state) %&gt;
  &lt;% fips_place = pstate.where(placeshort: @agency.city) %&gt;
  &lt;%= place = 'PLACE:' + fips_place.first.placefp %&gt;
  </code></pre>
  
  <p>But it works fine in the console when I run:</p>
  
  <pre><code>&gt; pstate = Place.where(statename: "CA")
  &gt; fips_place = pstate.where(placeshort: "Los Angeles")
  &gt; place = "PLACE: " + fips_place.first.placefp
  =&gt; "PLACE: 85292" 
  </code></pre>
  
  <p>controllers/agencies_controller.rb:</p>
  
  <pre><code>def set_agency
      @agency = Agency.find(params[:id])
  end
  </code></pre>
  
  <p>models/agency.rb:</p>
  
  <pre><code>class Agency &lt; ActiveRecord::Base
      has_one :place
      ...
  end
  </code></pre>
  
  <p>model/place.rb:</p>
  
  <pre><code>class Place &lt; ActiveRecord::Base
      belongs_to :agency
  end
  </code></pre>