0.06
No release in over 3 years
Low commit activity in last 3 years
There's a lot of open issues
This Gem gives you access to a signature pad form helper so you can save touchpad signatures as encoded png data
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 5.0
>= 0
~> 10.0
~> 3.0
 Project Readme

JohnHancock

Build Status

Saving signatures has never been easier!

Installation

Add this line to your application's Gemfile:

gem 'john_hancock'

And then execute:

$ bundle

Or install it yourself as:

$ gem install john_hancock

Setup (< Rails 7)

With the gem installed, simply include it in the relevant JS manifest

//= require john_hancock

Setup (Rails 7 and above using Import Maps)

  1. In config/initializers/assets.rb add:
Rails.application.config.assets.precompile += %w(john_hancock.js)
  1. In config/importmap.rb add:
pin "john_hancock", to: 'john_hancock.js', preload: true
  1. Lastly, in app/javascript/application.js:
import "john_hancock"

Usage

Then you are free to use it in the view

<%= form_for @user do |f| %>
  <%= f.signature_field :signature %>
  <%= f.submit %>
<% end %>

Once this is saved, you can output the string as an image.

<%= image_tag @user.signature %>

The signature_field method generates a canvas as well as a hidden field. If you would like more flexibility in the placement of these elements you can use them separately.

<%= form_for @user do |f| %>
  <%= f.signature_canvas %>
  <p>some text about the form</p>
  <%= f.hidden_signature_field :signature %>
  <%= f.submit %>
<% end %>

Example

Example

Credit

This gem is maintained by Brandon Lawrence and Ben Miller.

The underlying JS library, Signature Pad, is written by Thomas J Bradley.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Brantron/john_hancock.

License

The gem is available as open source under the terms of the MIT License.