18

I'm using rails 3. In production rails nicely handles exceptions and loads my static 404.html, 500.html etc files from my public directory. However, it loads these files into my layouts/application.html.erb file. I am looking for a way to instruct rails to load these files WITHOUT using my application layout - e.g. just serve the static html file and nothing else. What is the best way to accomplish this?

thanks!

istan
  • 1,349
  • 3
  • 21
  • 36

2 Answers2

61

render :file => 'public/404.html', :status => :not_found, :layout => false

mikdiet
  • 9,859
  • 8
  • 59
  • 68
2

For an advanced approach working within the Rails framework. Update your routes file:

get "/404", to: "errors#error_404"
get "/500", to: "errors#error_500"

Add an ErrorsController with:

layout false

def error_404
  render status: 404
end

def error_500
  render status: 500
end

Then within the app/views/errors/ add your error_404.erb and error_500.erb files along with a snazy image and a search bar.

More info here.

Shadoath
  • 720
  • 1
  • 15
  • 31