我的 Rails 控制器中有以下代码:
@main_mastertest = $connection.execute("SELECT * FROM builds;")
@l2_tmp_mastertest = Array.new
@l2_tmp_mastertest = @main_mastertest.map {|y|[y[0]]}
@l2_mastertest = Array.new
@l2_mastertest = @l2_tmp_mastertest.inject(Hash.new(0)) { |hash,element|
hash[element] +=1
hash }
@l2_mastertest = @l2_mastertest.sort_by { |x, _| x }.reverse
在那之后,我尝试在我看来做这样的事情:
<% @l2_mastertest.each_with_index do |row1, index1| %>
<% @l2_mastertest.each_with_index do |row2, index2| %>
<% if row2[0][ /(\d+\.\d+)/ ].to_s == row1[0].to_s %> # LINE X
..................
<% end %>
<% end %>
<% end %>
但它在 X 行给了我一个错误说:can't convert Regexp into Integer