Skip to content

Commit

Permalink
Get QR code to show up on the Field Slip show page
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-nathan committed Mar 26, 2024
1 parent a2a9bb1 commit 5e0bd16
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ gem("fastimage")
# for detecting file type of uploaded images
gem("mimemagic")

# QR code support for field slips
gem("rqrcode")

# for creating zip files
# RubyZip 3.0 is coming!
# **********************
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
chunky_png (1.4.0)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crack (1.0.0)
Expand Down Expand Up @@ -247,6 +248,10 @@ GEM
requestjs-rails (0.0.11)
railties (>= 6.1.0)
rexml (3.2.6)
rqrcode (2.2.0)
chunky_png (~> 1.0)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rtf (0.3.3)
rubocop (1.62.1)
json (~> 2.3)
Expand Down Expand Up @@ -391,6 +396,7 @@ DEPENDENCIES
railties (~> 7.1.3)
redis (~> 4.0)
requestjs-rails
rqrcode
rtf
rubocop
rubocop-performance
Expand Down
12 changes: 12 additions & 0 deletions app/models/field_slip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ def find_projects

result.unshift([project.title, project.id])
end

def qr_code(path)
qr = RQRCode::QRCode.new(path, level: :m)
qr.as_svg(
color: "000",
shape_rendering: "crispEdges",
module_size: 3,
standalone: true,
use_path: true,
fill: :white
)
end
end
4 changes: 4 additions & 0 deletions app/views/controllers/field_slips/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

<h1><%= "#{:FIELD_SLIP.t}: #{@field_slip.code}" %></h1>

<div>
<%= @field_slip.qr_code(field_slip_url(@field_slip)).html_safe %>
</div>

<%= render @field_slip %>

<div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ def route_actions_hash
as: "glossary_term_versions")

# ----- Field Slip Records: standard actions --------------------------------
resources :field_slips
get("qr/:id", to: "field_slips#show", id: /.*[^\d.-].*/)
resources :field_slips

# ----- Herbaria: standard actions -------------------------------------------
namespace :herbaria do
Expand Down

0 comments on commit 5e0bd16

Please sign in to comment.