Ruby on rails rails中作为参数的数组

Ruby on rails rails中作为参数的数组,ruby-on-rails,arrays,arguments,Ruby On Rails,Arrays,Arguments,您好,我想在rails中传递数组作为少量参数 下面是我希望运行的代码,但我得到的参数很少 query_string = "date_to > ? AND date_from < ?" var_array = [date_from, date_to] CreditType.find(type).formulas.where(query_string, var_array.each).exists? // is there a way to loop trought array and

您好,我想在rails中传递数组作为少量参数

下面是我希望运行的代码,但我得到的参数很少

query_string = "date_to > ? AND date_from < ?"
var_array = [date_from, date_to]

CreditType.find(type).formulas.where(query_string, var_array.each).exists? // is there a way to loop trought array and pass all elements as arguments?
query\u string=“date\u to>”和date\u from<?”
var\u数组=[date\u from,date\u to]
CreditType.find(type).formulas.where(查询字符串,变量数组.each).是否存在?//有没有办法循环trought数组并将所有元素作为参数传递?

这可能吗?我尝试了不同的方法,但似乎没有任何效果,我需要这种代码的和平是动态的<代码>查询字符串和变量数组可能会更改。那么有没有办法做到这一点呢?谢谢:)

您可以使用所谓的splat操作符
*
后跟数组,将数组的所有条目作为逗号分隔的参数传递

试试这个:

 CreditType.find(type).formulas.where(query_string, *var_array).exists?