我在一個破碎的地方。我能夠從@ set1中獲得數組,現在需要比較@ set1和@ set2,並查看有多少匹配。我可以讓@ array1正常工作,如果我在@ array2中有一個數組中的靜態數字,但不是當我使其變爲動態時。需要從陣列中找到匹配的控制器! Ruby on Rails
我需要一種方法來比較這兩個數組,並且現在處於虧損狀態!
def show
@set1 = Set1.find(params[:id])
@set2 = Set2.where(:date => @set1.date)
@array1 = [Set1.find(params[:id]).let1, Set1.find(params[:id]).let2]
@array2 = [Winnings.where(:date => @set1.date).let1, Winnings.where(:date => @set1.date).let2]
@intersection = @array1 & @array2
end
在找到起點:http://stackoverflow.com/questions/5013880/ruby-compare- 2-arrays-for-matches-and-count-the-number-of-match-instances – nathanielelliott
http://stackoverflow.com/questions/19107761/activerecord-find-and-only-return-selected-columns-aligned- with-id – nathanielelliott