1

How could i render my error pages in production mode, so that they are in same layout as rest pages? For example, not 404 as standart

<h1>The page you were looking for doesn't exist.</h1>
    <p>You may have mistyped the address or the page may have moved.</p>

without any layout, but this message in my layout (called application.html.haml)?

Is it real? And what and where i need to write? I google'd but for own layout didn't find good one....

i use rails 3.2.8, ruby 1.9.3

brabertaser19
  • 5,678
  • 16
  • 78
  • 184

2 Answers2

4

One solution would be this:

# In config/application.rb
config.exceptions_app = self.routes

# In routes
match "/404", to: "errors#not_found"
match "/500", to: "errors#server_error"

# app/controllers/errors_controller.rb

class ErrorsController < ApplicationController
  # Inherits layout from ApplicationController 

  def not_found
  end

  def server_error
  end
end

# app/views/errors/not_found.haml
%h1 Didn't find nothing!

# app/views/errors/server_error.haml
%h1 FUBAR!
mahatmanich
  • 10,791
  • 5
  • 63
  • 82
Jesper
  • 4,535
  • 2
  • 22
  • 34
  • Awesome answer, thanks. But there is a missing piece: `# app/config/environments/development.rb` `config.consider_all_requests_local = false` – Cyber Oliveira Oct 02 '15 at 15:27
  • It's also worth noting that the returned status code will be changed to '200' unless you explicitly set it on your controller. A simple `render status: 404` will do. – Cyber Oliveira Oct 02 '15 at 15:41
0

I use this method, you should find the same for Rails 3

http://henrik.nyh.se/2008/07/rails-404/

pierallard
  • 3,326
  • 3
  • 21
  • 48