parm530
12/7/2018 - 3:43 PM

404 NOT FOUND

How to redirect to urls to 404 when resource is not found

# 404 Error means that the resource you are trying to access is not found
# You can redirect from a controller action by either rendering a 404.html page or
# raising ActionController::RoutingError error

# Using a 404.html page
# inside your controller action, usually the ApplicationController
def render_not_found
  render :file => "#{Rails.root}/public/404.html", layout: false, status: :not_found
end

# Raising an ActionController::RoutingError
# Inside your controller action
def not_found
  raise ActionController::RoutingError.new("Not Found")
end

# You can then call this method inside another controller 
def show
  return not_found if some_condition
end