Fix issues with attaching QR code to email

This commit is contained in:
Petko Bordjukov 2019-10-13 14:38:03 +03:00
parent b5c88b1f8e
commit de45091c59
7 changed files with 49 additions and 12 deletions

View File

@ -62,6 +62,8 @@ gem "faraday"
gem "rqrcode" gem "rqrcode"
gem "draper"
group :development do group :development do
gem "spring" gem "spring"
gem "spring-commands-rspec" gem "spring-commands-rspec"

View File

@ -37,6 +37,10 @@ GEM
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.2.3) activemodel (5.2.3)
activesupport (= 5.2.3) activesupport (= 5.2.3)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (5.2.3) activerecord (5.2.3)
activemodel (= 5.2.3) activemodel (= 5.2.3)
activesupport (= 5.2.3) activesupport (= 5.2.3)
@ -139,6 +143,12 @@ GEM
devise (>= 4.6) devise (>= 4.6)
diff-lcs (1.3) diff-lcs (1.3)
docile (1.3.2) docile (1.3.2)
draper (3.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
activemodel-serializers-xml (>= 1.0)
activesupport (>= 5.0)
request_store (>= 1.0)
erubi (1.9.0) erubi (1.9.0)
execjs (2.7.0) execjs (2.7.0)
factory_bot (5.1.1) factory_bot (5.1.1)
@ -454,6 +464,7 @@ DEPENDENCIES
delorean delorean
devise devise
devise-i18n devise-i18n
draper
factory_bot_rails factory_bot_rails
faker faker
faraday faraday

View File

@ -1,10 +1,10 @@
class Public::EventFeedbackQrcodesController < Public::ApplicationController class Public::EventFeedbackQrcodesController < Public::ApplicationController
def show def show
event = current_conference.events.joins(:proposition).approved.find(params[:event_id]) event = current_conference.events.joins(:proposition).approved.find(params[:event_id]).decorate
respond_to do |format| respond_to do |format|
format.svg do format.svg do
render(inline: helpers.feedback_qr_code_as_svg(event.id), render(inline: event.feedback_qr_code_as_svg,
filename: "feedback_qr_code_#{event.id}.svg") filename: "feedback_qr_code_#{event.id}.svg")
end end
end end

View File

@ -0,0 +1,8 @@
class ApplicationDecorator < Draper::Decorator
# Define methods for all decorated objects.
# Helpers are accessed through `helpers` (aka `h`). For example:
#
# def percent_amount
# h.number_to_percentage object.amount, precision: 2
# end
end

View File

@ -0,0 +1,20 @@
class EventDecorator < Draper::Decorator
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end
def feedback_qr_code
RQRCode::QRCode.new(h.new_event_feedback_url(event_id: id), level: :l)
end
def feedback_qr_code_as_svg
feedback_qr_code.as_svg(shape_rendering: "crispEdges", module_size: 11, fill: "ffffff", offset: 10)
end
end

View File

@ -85,12 +85,4 @@ module ApplicationHelper
when 6 then t('ratings.excellent') when 6 then t('ratings.excellent')
end end
end end
def feedback_qr_code(event_id)
RQRCode::QRCode.new(new_event_feedback_url(event_id: event_id), level: :l)
end
def feedback_qr_code_as_svg(event_id)
feedback_qr_code(event_id).as_svg(shape_rendering: "crispEdges", module_size: 11, fill: "ffffff", offset: 10)
end
end end

View File

@ -1,11 +1,15 @@
class EventMailer < ActionMailer::Base class EventMailer < ActionMailer::Base
helper ApplicationHelper
def confirmation_request(event) def confirmation_request(event)
@event = event @event = event.decorate
I18n.locale = @event.proposer.language I18n.locale = @event.proposer.language
attachments['feedback-link-qr-code.svg'] = { attachments['feedback-link-qr-code.svg'] = {
mime_type: 'image/svg+xml', mime_type: 'image/svg+xml',
content: helpers.feedback_qr_code_as_svg(@event.id) content: @event.feedback_qr_code_as_svg
} }
mail to: @event.proposer.email, mail to: @event.proposer.email,
from: "program@openfest.org", from: "program@openfest.org",
subject: I18n.t("event_mailer.acceptance_notification.subject", subject: I18n.t("event_mailer.acceptance_notification.subject",