[N00b] find/paginate with :condition values in an array

Try this:

:conditions => ['WHERE bug_id IN (?)', :bug_id_list],

Olie D. wrote:

The problem is that you are passing a symbol to conditions not the array. The problem is with your link_to and the array. You need to look at params and see what params[:bug_id_list] is. I should have looked at the code I sent you more carefully. If params[:bug_id_list] is indeed an array, this will work:

:conditions => ['WHERE bug_id IN (?)', params[:bug_id_list]],

Olie D. wrote:

Btw, you can look at your params array at the top of the request in development.log. You could also look at the particular key in question like this:

logger.debug "params[:bug_id_list] = " + params[:bug_id_list].inspect

William Pratt wrote:

Something is not right here, because this does work. What do you see in your logs if you try this?

logger.debug "params[:bug_id_list].class = " + params[:bug_id_list].class

I’m guessing that you are not getting an array because if were getting an array of numbers, it would output them as a comma delimited string. If this is a String separated by /'s, you could do:

:conditions => ['WHERE bug_id IN (?)', params[:bug_id_list].split('/']),

I have never tried to pass an array in a link in link_to like you are doing so I’m not sure what the result is. Maybe you should rethink the way you are sending your array?

Olie D. wrote:

I just wrote a simple test to emulate what you are doing and I got the correct result. I’m not sure whats going on in your case. Can you show the output of the inspect on the params[:bug_id_list].inspect ?

William Pratt wrote:

You don't put "WHERE" in the conditions. AR takes care of that for you.

   :conditions => ['bug_id IN (?)', params[:bug_id_list]],

wow, I completely missed that…that would definitely do it. thats what I get for answering posts and trying to work at the same time :slight_smile:

Bob Showalter wrote: