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:
     class Transaction < ApplicationRecord
         # …
    		
         def amount=(value)
             if value.is_a? Hash
                 # do stuff with value[1] etc
             end
    	
             super(value)
         end
    		
         # …
     end
    
  3. Profit