title: Why won't my rails app work when pushing to Heroku: "ActionView::Template::Error (undefined method `toilet_available' for nil:NilClass)"?
body: <p>I'm building a store locator app in Rails 5 that uses the Open Street Map API and leaflet-rails gem. Everything works as expected in development environment but when I push to Heroku I get the "We're sorry, but something went wrong." message. I created a function where you can sort stores by whether they have a toilet or not and this seams to be where the problem lies. The Heroku logs show the following:</p>
  
  <pre><code>2018-09-12T22:02:39.751563+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123] Completed 500 Internal Server Error in 624ms (ActiveRecord: 119.5ms)
  2018-09-12T22:02:39.706503+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]   Toilet Load (29.5ms)  SELECT "toilets".* FROM "toilets"
  2018-09-12T22:02:39.772904+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]
  2018-09-12T22:02:39.773276+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]     29:                                             &lt;li&gt;&lt;%= link_to "Log In", new_user_session_path %&gt; &lt;/li&gt;
  2018-09-12T22:02:39.772915+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123] ActionView::Template::Error (undefined method `toilet_available' for nil:NilClass):
  2018-09-12T22:02:39.773280+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]     30:                                             &lt;li&gt;&lt;%= link_to "Add Spaeti", new_user_registration_path %&gt; &lt;/li&gt;
  2018-09-12T22:02:39.773283+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]     31:                                     &lt;% end %&gt;
  2018-09-12T22:02:39.773285+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]     32:                                     &lt;li&gt;&lt;%= link_to "Spaetis with toilets", stores_path(toilet: Toilet.all[0].toilet_available) %&gt;&lt;/li&gt;
  2018-09-12T22:02:39.773288+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]     33:                             &lt;/ul&gt;
  2018-09-12T22:02:39.773290+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]     34:                     &lt;/div&gt;
  2018-09-12T22:02:39.773292+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]     35:             &lt;/nav&gt;
  2018-09-12T22:02:39.773336+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123]
  2018-09-12T22:02:39.773423+00:00 app[web.1]: [30a84d17-6a5a-4b3d-b21f-ee08babfd123] app/views/layouts/application.html.erb:32:in `_app_views_layouts_application_html_erb__2166090761148733231_41993540'
  </code></pre>
  
  <p>When I remove this line from the view the app loads fine: <code>&lt;li&gt;&lt;%= link_to "Spaetis with toilets", stores_path(toilet: Toilet.all[0].toilet_available) %&gt;&lt;/li&gt;</code></p>
  
  <p>What could be causing this error? I've been tearing my hair out for a good few days now...</p>
  
  <p>Store Model:</p>
  
  <pre><code>class Store &lt; ApplicationRecord
      belongs_to :user
      belongs_to :toilet
  
      validates :name, presence: true
      validates :address, presence: true
      validates :address_line2, presence: true
      validates :address_line3, presence: true
      validates :toilet, presence: true
      # validates :latitude, presence: true
      # validates :longitude, presence: true
      validates :beer_cost, format: { with: /\A\d+(?:\.\d{0,2})?\z/ }, numericality: { greater_than: 0, less_than: 10 }
      validates :latitude, :presence =&gt; {message: "Not a valid location, please check name address &amp; country fields" }
  
      def full_address
        [address, address_line2, address_line3].compact.join(', ')
      end
      geocoded_by :full_address
      before_validation :geocode,
        :if =&gt; lambda{ |obj| obj.address_changed? }
  
      def capitalize_name
          name.capitalize
      end
  
      def capitalize_address
          address.capitalize
      end
  end
  </code></pre>
  
  <p>Toilet Model:</p>
  
  <pre><code>class Toilet &lt; ApplicationRecord
      has_many :stores
  end
  </code></pre>
  
  <p>Schema.rb:</p>
  
  <pre><code>ActiveRecord::Schema.define(version: 20180814220216) do
  
    create_table "stores", force: :cascade do |t|
      t.string "name"
      t.string "address"
      t.float "beer_cost"
      t.text "facilities"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.float "latitude"
      t.float "longitude"
      t.boolean "toilet"
      t.string "address_line2"
      t.integer "user_id"
      t.integer "toilet_id"
      t.string "address_line3"
    end
  
    create_table "toilets", force: :cascade do |t|
      t.string "toilet_available"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end
  
    create_table "users", force: :cascade do |t|
      t.string "email", default: "", null: false
      t.string "encrypted_password", default: "", null: false
      t.string "reset_password_token"
      t.datetime "reset_password_sent_at"
      t.datetime "remember_created_at"
      t.integer "sign_in_count", default: 0, null: false
      t.datetime "current_sign_in_at"
      t.datetime "last_sign_in_at"
      t.string "current_sign_in_ip"
      t.string "last_sign_in_ip"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.index ["email"], name: "index_users_on_email", unique: true
      t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
    end
  
  end
  </code></pre>
  
  <p>Github repo: <a href="https://github.com/catsinspacesuits/Spaeti-App" rel="nofollow noreferrer">https://github.com/catsinspacesuits/Spaeti-App</a></p>