Sha256: 24adda49c01f6380bd915f973b517744094a806a2cfdec004a6ceabbd74318da

Contents?: true

Size: 981 Bytes

Versions: 3

Compression:

Stored size: 981 Bytes

Contents

# frozen-string-literal: true

module EncryptedFormFields
  module Helpers
    module FormTagHelper
      # Creates a hidden input field used with encrypted content. Use this field
      # to transmit data that user shouldn't see or be able to modify.
      #
      # ==== Options
      # * Creates standard HTML attributes for the tag.
      #
      # ==== Examples
      #   encrypted_field_tag 'email_verified_at', Time.now.to_s
      #   => <input id="email_verified_at" name="_encrypted_email_verified_at" type="hidden" value="[encrypted]" />
      def encrypted_field_tag(name, value = nil, options = {})
        encrypted_value = EncryptedFormFields.encrypt_and_sign(value)
        prefixed_name = EncryptedFormFields.prefix_name(name.to_s)
        tag :input, {
          "type" => "hidden",
          "name" => prefixed_name,
          "id" => sanitize_to_id(name),
          "value" => encrypted_value
        }.update(options.stringify_keys)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
encrypted_form_fields-1.0.0 lib/encrypted_form_fields/helpers/form_tag_helper.rb
encrypted_form_fields-0.2.4 lib/encrypted_form_fields/helpers/form_tag_helper.rb
encrypted_form_fields-0.2.3 lib/encrypted_form_fields/helpers/form_tag_helper.rb