Module: SignedForm::FormBuilder
- Defined in:
- lib/signed_form/form_builder.rb
Constant Summary collapse
- FIELDS_TO_SIGN =
[:select, :collection_select, :grouped_collection_select, :time_zone_select, :collection_radio_buttons, :collection_check_boxes, :date_select, :datetime_select, :time_select, :text_field, :password_field, :hidden_field, :file_field, :text_area, :check_box, :radio_button, :color_field, :telephone_field, :phone_field, :date_field, :time_field, :datetime_field, :datetime_local_field, :month_field, :week_field, :url_field, :email_field, :number_field, :range_field]
- BUILDERS =
Hash.new do |h,k| h[k] = Class.new(k) do include FormBuilder end end
Instance Method Summary collapse
-
#add_signed_fields(*fields) ⇒ Object
This method is used to add additional fields to sign.
-
#fields_for(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
Wrapper for Rails fields_for.
- #form_signature_tag ⇒ Object
- #initialize ⇒ Object
Instance Method Details
#add_signed_fields(*fields) ⇒ Object
This method is used to add additional fields to sign. A usecase for this may be if you want to add fields later with javascript.
78 79 80 81 |
# File 'lib/signed_form/form_builder.rb', line 78 def add_signed_fields(*fields) @signed_attributes_context.push(*fields) [:digest] << @template if [:digest] end |
#fields_for(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
Wrapper for Rails fields_for
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/signed_form/form_builder.rb', line 54 def fields_for(record_name, record_object = nil, = {}, &block) hash = {} array = [] if nested_attributes_association?(record_name) hash["#{record_name}_attributes"] = [:signed_attributes_context] = array else hash[record_name] = [:signed_attributes_context] = array end add_signed_fields hash content = super array.uniq! content end |
#form_signature_tag ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/signed_form/form_builder.rb', line 41 def form_signature_tag @signed_attributes.each { |k,v| v.uniq! if v.is_a?(Array) } encoded_data = Base64.strict_encode64 Marshal.dump(@signed_attributes) hmac = SignedForm::HMAC.new(secret_key: SignedForm.secret_key) signature = hmac.create(encoded_data) token = "#{encoded_data}--#{signature}" %(<input type="hidden" name="form_signature" value="#{token}" />\n).html_safe end |
#initialize ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/signed_form/form_builder.rb', line 30 def initialize(*) super if [:signed_attributes_context] @signed_attributes_context = [:signed_attributes_context] else @signed_attributes = { object_name => [] } @signed_attributes_context = @signed_attributes[object_name] prepare_signed_attributes_hash end end |