Jonathan Bennett

Backing a single field with multiple inputs

TLDR:

  1. Change the inputs to include an index and optional type ie amount => amount(1i)
  2. Add a setter method in the model and handle a hash input:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
     class Transaction < ApplicationRecord
         # …
    		
         def amount=(value)
             if value.is_a? Hash
                 # do stuff with value[1] etc
             end
    	
             super(value)
         end
    		
         # …
     end
    
  3. Profit