你好,我希望能够在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_string
和var_arrays
可能会改变。所以有没有一种方法可以实现?谢谢 :)