瀏覽代碼

Handle passing routes to react-router/404 as necessary

Andrew Swistak 6 年之前
父節點
當前提交
d31066332a
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 6 1
      app/controllers/api/v1/application_controller.rb
  2. 4 0
      config/routes.rb

+ 6 - 1
app/controllers/api/v1/application_controller.rb

@@ -7,6 +7,11 @@ class API::V1::ApplicationController < ActionController::API
 
   rescue_from StandardError, with: :handle_unhandled_api_error
 
+  def not_found
+    @error = APIError::BaseError.new("The requested resource was not found")
+    render partial: 'error', status: :not_found
+  end
+
   private
 
   def handle_unhandled_api_error(e)
@@ -17,6 +22,6 @@ class API::V1::ApplicationController < ActionController::API
   end
 
   def set_default_response_format
-    #request.format = :json
+    request.format = :json
   end
 end

+ 4 - 0
config/routes.rb

@@ -11,5 +11,9 @@ Rails.application.routes.draw do
         end
       end
     end
+
+    match '*path', to: 'v1/application#not_found', via: :all
   end
+
+  get '*path', to: 'welcome#root'
 end