From 47d2ec99b19d079073cb5c0aa8eb413a42eeec60 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sun, 22 Oct 2017 23:24:28 +0300 Subject: [PATCH] Add event feedback QR codes --- Gemfile | 2 ++ Gemfile.lock | 4 ++++ .../public/event_feedback_qrcodes_controller.rb | 13 +++++++++++++ app/views/api/events/index.jbuilder | 1 + config/initializers/mime_types.rb | 2 ++ config/routes.rb | 1 + 6 files changed, 23 insertions(+) create mode 100644 app/controllers/public/event_feedback_qrcodes_controller.rb diff --git a/Gemfile b/Gemfile index 42f20dd..d78616d 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,8 @@ gem 'search_object' gem 'faraday' +gem 'rqrcode' + group :development do gem 'spring' gem 'spring-commands-rspec' diff --git a/Gemfile.lock b/Gemfile.lock index d0d8f5e..b7fec7f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,6 +89,7 @@ GEM mime-types (>= 1.16) mimemagic (>= 0.3.0) choice (0.2.0) + chunky_png (1.3.8) coderay (1.1.1) coffee-rails (4.2.1) coffee-script (>= 2.2.0) @@ -284,6 +285,8 @@ GEM mime-types (>= 1.16, < 3.0) netrc (~> 0.7) rmagick (2.16.0) + rqrcode (0.10.1) + chunky_png (~> 1.0) rspec (3.5.0) rspec-core (~> 3.5.0) rspec-expectations (~> 3.5.0) @@ -423,6 +426,7 @@ DEPENDENCIES refile refile-mini_magick rmagick + rqrcode rspec-rails sass-rails search_object diff --git a/app/controllers/public/event_feedback_qrcodes_controller.rb b/app/controllers/public/event_feedback_qrcodes_controller.rb new file mode 100644 index 0000000..2ec1ae1 --- /dev/null +++ b/app/controllers/public/event_feedback_qrcodes_controller.rb @@ -0,0 +1,13 @@ +class Public::EventFeedbackQrcodesController < Public::ApplicationController + def show + event = current_conference.events.joins(:proposition).approved.find(params[:event_id]) + @qr = RQRCode::QRCode.new(new_event_feedback_url(event_id: event.id), level: :l) + + respond_to do |format| + format.svg do + render(inline: @qr.as_svg(shape_rendering: 'crispEdges', module_size: 11, fill: 'ffffff', offset: 10), + filename: "feedback_qr_code_#{event.id}.svg") + end + end + end +end diff --git a/app/views/api/events/index.jbuilder b/app/views/api/events/index.jbuilder index 72f5a0b..a53ef36 100644 --- a/app/views/api/events/index.jbuilder +++ b/app/views/api/events/index.jbuilder @@ -10,5 +10,6 @@ json.track_id event.track_id json.participant_user_ids event.participations.map(&:participant_id) json.feedback_url new_event_feedback_url(event_id: event.id) + json.feedback_qr_code_url event_feedback_qr_code_url(event_id: event.id, format: :svg) end end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc18996..f4c73f9 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -2,3 +2,5 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf + +Mime::Type.register "image/svg+xml", :svg diff --git a/config/routes.rb b/config/routes.rb index 893252b..7167f63 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ Rails.application.routes.draw do resource :personal_profile, path: 'profile' resources :events do resources :feedbacks, controller: 'event_feedbacks', only: [:new, :create] + resource :feedback_qr_code, controller: 'event_feedback_qrcodes', only: :show member do get :confirm end