let say I have 2 arrays @arr1 = [10,20,30,40] @arr2 = [30,40,50,60]
In rails controller I am trying to find both diffs and according it add or remove records.
If I do in console simple @diff1 = (@arr1 - @arr2) I get correct result [10,20]
if I do in rails controller the same, I get whole @arr1 instead of @diff1 so I tried simple puts (@arr1 - @arr2) but with wrong result
here is the sample code:
@associates = params[:associate_to]
@coordinators = @guild.coordinators.pluck(:coordinator_id)
@to_add = (@associates-@coordinators)
@to_remove = (@coordinators-@associates)
puts "first array"
puts @associates
puts "----"
puts "second array"
puts @coordinators
puts "-----"
puts "calculation"
puts (@associates-@coordinators)
puts "result"
puts @to_add
and here is result from rails server
what am I doing wrong?

@to_add = (@associates - @coordinators)putsplease useinspect- it can make all the difference. So:puts @associates.inspectandputs (@associates - @coordinators).inspect-> sometime's Rails implicitto_scan cause two different things to appear to be the same when they're really not. So do this now for all yourputss and then show us the new results.@associatescomes fromparamsand@coordinatorscomes from database records; It's very likely@associatesis an array of strings while@coordinatorsis an array of integers. Maybe try@associates = params[:associate_to].map(&:to_i)inspectis an excellent thing when usingputs... it will instantly show you the difference...