title: Getting 500 error trying to load view through controller rails
body: <p>Im trying to get a rails view to load through an ajax call. I get this error:</p>
  
  <pre><code>Started POST "/schools/municipalities" for 127.0.0.1 at 2013-03-07 13:40:11 +0100
  Processing by SchoolsController#municipalities as HTML
    Parameters: {"Hallands län"=&gt;nil}
    School Load (1.9ms)  SELECT "schools".* FROM "schools" WHERE "schools"."region" IS NULL
    Rendered schools/municipalities.html.erb (0.7ms)
  Completed 500 Internal Server Error in 7ms
  
  ActionView::Template::Error (undefined method `map' for nil:NilClass):
      1:
      2: &lt;%= form_tag 'schools' do %&gt;
      3: &lt;p&gt;&lt;%= select_tag(:municipalities, options_from_collection_for_select(@municipalities, :municipality, :municipality )) %&gt;
      4: &lt;/p&gt;&lt;p&gt;
      5: &lt;%= submit_tag 'Nästa', :class=&gt; 'btn btn-primary' %&gt;
      6:  &lt;/p&gt;
    app/views/schools/municipalities.html.erb:3:in `block in _app_views_schools_municipalities_html_erb___826836004410337613_70142825095080'
    app/views/schools/municipalities.html.erb:2:in `_app_views_schools_municipalities_html_erb___826836004410337613_70142825095080'
    app/controllers/schools_controller.rb:10:in `municipalities'
  
  
    Rendered /Users/gjores/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.6ms)
    Rendered /Users/gjores/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.4ms)
    Rendered /Users/gjores/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (12.8ms)
  </code></pre>
  
  <p>I can se that Im getting the params all wrong. And im been trying to work out how this is supposed to be. </p>
  
  <p><strong>school.js</strong></p>
  
  <pre><code>$(document).ready(function() {
      $('#region').change(function(){
          region = $(this).val();
          $.ajax({
              url:  "municipalities",
              cashe: false,
              data: region,
              dataType: "HTML",
              type: 'POST',
  
              success: function(html){
            $("#append").append(html);}
  
          });
      });
  });
  </code></pre>
  
  <p><strong>schools.rb controller</strong></p>
  
  <pre><code>class SchoolsController &lt; ApplicationController
    def region
      @regions = School.select(:region).uniq.order(:region)
  
    end
  
    def municipalities
      region = params[:region]
      @municipalities = School.where(:region =&gt; params[:region]).uniq!{|e| e[:municipality]} 
      render :layout =&gt; false
  
    end
  
    def schools
      @user = current_user
      @schools = School.where(:municipality =&gt; params[:municipalities])
      render :layout =&gt; false
    end
  end 
  </code></pre>
  
  <p><strong>Region view</strong></p>
  
  <pre><code>&lt;%= form_tag 'municipalities' do %&gt;
  &lt;p&gt;&lt;%= select_tag(:region, options_from_collection_for_select(@regions, 'region', 'region')) %&gt;
  &lt;/p&gt;
      &lt;div id="append"&gt;
  
      &lt;/div&gt;
  &lt;p&gt;
  &lt;%= submit_tag 'Nästa', :class=&gt; 'btn btn-primary' %&gt;
      &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>Municipalities view</strong></p>
  
  <pre><code>&lt;%= form_tag 'schools' do %&gt;
  &lt;p&gt;&lt;%= select_tag(:municipalities, options_from_collection_for_select(@municipalities, :municipality, :municipality )) %&gt;
  &lt;/p&gt;&lt;p&gt;
  &lt;%= submit_tag 'Nästa', :class=&gt; 'btn btn-primary' %&gt;
      &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>