Browse Source

[rails] Route rack response for plaintext (#9041)

Rails allows short circuiting responses in the router.
Petrik de Heus 1 year ago
parent
commit
2a6d458c73

+ 0 - 9
frameworks/Ruby/rails/app/controllers/plaintext_controller.rb

@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-class PlaintextController < ApplicationControllerMetal
-  def index
-    add_headers
-    self.content_type = 'text/plain'
-    self.response_body = 'Hello, World!'
-  end
-end

+ 9 - 1
frameworks/Ruby/rails/config/routes.rb

@@ -6,6 +6,14 @@ Rails.application.routes.draw do
   get "queries", to: "hello_world#query"
   get "fortunes", to: "hello_world#fortune"
   get "updates", to: "hello_world#update"
-  get "plaintext", to: PlaintextController.action(:index)
+  get "plaintext", to: ->(env) do
+    [200,
+     {
+       'Content-Type' => 'text/plain',
+       'Date' => Time.now.httpdate,
+       'Server' => 'Rails'
+     },
+     ['Hello, World!']]
+  end
   get "cached", to: "hello_world#cached_query"
 end