Skip to content

Instantly share code, notes, and snippets.

@kulte
Created February 17, 2013 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kulte/4969947 to your computer and use it in GitHub Desktop.
Save kulte/4969947 to your computer and use it in GitHub Desktop.
module ActionView
module Helpers
module FormHelper
def encrypted_text_field(object_name, method, options = {})
InstanceTag.new(object_name, method, self, options.delete(:object)).to_encrypted_input_field_tag("text", options)
end
class InstanceTag
def to_encrypted_input_field_tag(field_type, options = {})
options = options.stringify_keys
options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
options = DEFAULT_FIELD_OPTIONS.merge(options)
if field_type == "hidden"
options.delete("size")
end
options["type"] ||= field_type
options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file"
options["value"] &&= ERB::Util.html_escape(options["value"])
add_default_name_and_id(options)
tag("input", options.merge({ "data-encrypted-name" => options.delete("name") }))
end
end
end
class FormBuilder
def encrypted_text_field(method, options = {})
@template.encrypted_text_field(@object_name, method, objectify_options(options))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment