From b8e93c4f8a6b87866ce3e0b50dc7645f0d926219 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 19 Oct 2024 19:31:48 -0700 Subject: [PATCH] Extract render svg as a real renderer --- app/controllers/accounts/join_codes_controller.rb | 8 +------- config/initializers/action_controller_svg_renderer.rb | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 config/initializers/action_controller_svg_renderer.rb diff --git a/app/controllers/accounts/join_codes_controller.rb b/app/controllers/accounts/join_codes_controller.rb index bcb474ee2..52e909de8 100644 --- a/app/controllers/accounts/join_codes_controller.rb +++ b/app/controllers/accounts/join_codes_controller.rb @@ -1,16 +1,10 @@ class Accounts::JoinCodesController < ApplicationController def show - render_svg RQRCode::QRCode.new(join_url(Current.account.join_code)).as_svg(viewbox: true, fill: :white, color: :black) + render svg: RQRCode::QRCode.new(join_url(Current.account.join_code)).as_svg(viewbox: true, fill: :white, color: :black) end def update Current.account.reset_join_code redirect_to account_users_path end - - private - # FIXME: Upstream to Rails as render svg: - def render_svg(svg) - render content_type: Mime[:svg], body: svg - end end diff --git a/config/initializers/action_controller_svg_renderer.rb b/config/initializers/action_controller_svg_renderer.rb new file mode 100644 index 000000000..c10e16d20 --- /dev/null +++ b/config/initializers/action_controller_svg_renderer.rb @@ -0,0 +1,7 @@ +# FIXME: Upstream to Rails +Rails.application.config.after_initialize do + ActionController.add_renderer :svg do |svg, options| + self.content_type = Mime[:svg] if media_type.nil? + svg + end +end