Extract render svg as a real renderer

This commit is contained in:
David Heinemeier Hansson
2024-10-19 19:31:48 -07:00
parent 15b0d6e818
commit b8e93c4f8a
2 changed files with 8 additions and 7 deletions
@@ -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
@@ -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