title: Rails: undefined method `map' for nil:NilClass
body: <p>I know that there are a lot of questions with the same error but i didn't find any that solves my problem. So, I have a "Bairro" and there are "Clientes" and "Imoveis" thats belongs to. The problem is that creating a customer "Cliente" works just fine, but when I go to create a "Imovel" I have the error: 
  <br/>undefined method `map' for nil:NilClass and highlight on: </p>
  
  <pre><code>&lt;%= f.collection_select :bairro_id, @bairros, :id, :nome, {} , class: "form-control" %&gt;
  </code></pre>
  
  <p>The Imovel.rb is like this:</p>
  
  <pre><code>class Imovel &lt; ApplicationRecord
    belongs_to :bairro
    belongs_to :cliente
  end
  </code></pre>
  
  <p>In the controller I have this:</p>
  
  <pre><code>def new
    @imovel = Imovel.new
    @bairros = Bairro.all
    @clientes = Cliente.all
  end
  
  def edit
    @bairros = Bairro.all 
    @clientes = Clientes.all 
  end
  
  def update
    @bairros = Bairro.all
    respond_to do |format|
      if @imovel.update(imovel_params)
        format.html { redirect_to @imovel}
      else
        format.html { render :edit }
      end
    end
  end
  
  
  def create
      @bairros = Bairro.all
      @imovel = Imovel.new(imovel_params)
      respond_to do |format|
        if @imovel.save
          format.html { redirect_to @imovel}
          format.json { render :show, status: :created, location: @imovel }
        else
          format.html { render :new }
        end
      end
    end
  </code></pre>
  
  <p>Usually this error happens when @bairros = Bairro.all is not defined, but not in this case. </p>
  
  <p>The view opens just fine, I can edit to, but when I going to save, the error happens.
  How can I solve this?</p>