How do you return 503 Service Unavailable in Rails for the entire application?

Also, how do you do the same for specific controllers?


Solution 1:

You can use head

head 503
# or
head :service_unavailable

Solution 2:

For the entire application:

# ApplicationController
before_filter :return_unavailable_status

private
  def return_unavailable_status
    render :nothing => true, :status => :service_unavailable
  end

If you wanted a custom error page, you could do:

render 'custom_unavailable_page', :status => :service_unavailable    

If you don't want it for specific controllers:

# SomeController
skip_before_filter :return_unavailable_status