title: Rails 3.1 and static pages
body: <p>I'm just in the middle of upgrading a large application from Rails 3 to Rails 3.1 and struck a problem with my implementation of the pages controller:</p>
  
  <pre><code>  when templates doesnt exist
      should render the 404 page (FAILED - 1)
  
  Failures:
  
    1) PagesController automatic paths when templates doesnt exist should render the 404 page
       Failure/Error: get 'base_page_processor', :base_page =&gt; 'something_that_doesnt_exist'
       NoMethodError:
         undefined method `map' for "pages":String
       # ./app/controllers/pages_controller.rb:5:in `base_page_processor'
       # ./spec/controllers/pages_controller_spec.rb:37:in `block (3 levels) in &lt;top (required)&gt;'
  
  Finished in 0.10557 seconds
  4 examples, 1 failure
  
  Failed examples:
  
  rspec ./spec/controllers/pages_controller_spec.rb:36 # PagesController automatic paths when templates doesnt exist should render the 404 page
  </code></pre>
  
  <p>This did work in Rails 3.0. Something must of changed with the template_exists method. Here is the controller:</p>
  
  <pre><code>class PagesController &lt; ApplicationController
    def base_page_processor
      view_prefix = "pages"
  
      if params[:base_page].present? &amp;&amp; template_exists?(params[:base_page], view_prefix)
        render "#{view_prefix}/#{params[:base_page]}"
      else
        #TODO : Notify missing url via email error or error notification service
        render '/public/404.html', :status =&gt; 404
      end
    end
  end
  </code></pre>
  
  <p>Solution code:</p>
  
  <pre><code>class PagesController &lt; ApplicationController
    def base_page_processor
      view_prefix = ["pages"]
  
      if params[:base_page].present? &amp;&amp; template_exists?(params[:base_page], view_prefix)
        render "#{view_prefix[0]}/#{params[:base_page]}"
      else
        #TODO : Notify missing url via email error or error notification service
        render '/errors/404.html', :status =&gt; 404
      end
    end
  end
  </code></pre>
  
  <p>I also noticed that it wasn't rendering the error views (ie: /public/404.html) so I created a directory app/views/errors and put all the error static pages in there and just render them now. It works.</p>
  
  <p>Thanks Andrew.</p>