# Passing an array to a Ruby controller (from AJAX)

**URL:** <https://www.ruby-forum.com/t/passing-an-array-to-a-ruby-controller-from-ajax/132039>\
**Category:** Rails\
**Created:** [March 15, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/passing-an-array-to-a-ruby-controller-from-ajax/132039 "2008-03-15T19:53:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Backov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Backov](https://www.ruby-forum.com/u/Backov)\
**Post date:** [March 15, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/passing-an-array-to-a-ruby-controller-from-ajax/132039/1 "2008-03-15T19:53:03Z")

</div>

I thought I knew how to do this, but it’s not working. I’m passing an  
array of ids to a ruby controller with an HTTPService call… It’s  
getting the call but it’s only using the first value. The url is like  
so (GET for clarity)

/league/getopenleagues/dbg\_12345?friends=dbg\_12346&friends=dbg\_12347

In the controller I am grabbing those ids and shoving them into a find  
query in a comma seperated list so that I can do a “NOT IN” condition.  
I’m probably doing this poorly, but I’m doing it like this:

```
  friendsList = Array.new
  params[:friends].each do |friend|
    friendsList.push("'"+friend+"'");
  end

```

and then in the conditions I do:

network\_id NOT IN (#{friendsList.join(",")})

First off - is there a better way to do that without the intermediary  
steps? And also, why is this not working - it doesn’t think it’s an  
array?

---

<div class="post-metadata">

**Author:** ![Backov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Backov](https://www.ruby-forum.com/u/Backov)\
**Post date:** [March 16, 2008, 12:01pm UTC](https://www.ruby-forum.com/t/passing-an-array-to-a-ruby-controller-from-ajax/132039/2 "2008-03-16T12:01:12Z")

</div>

> First off - is there a better way to do that without the intermediary  
> steps? And also, why is this not working - it doesn’t think it’s an  
> array?

IIRC you need to call your parameter friends[] for rails to treat it  
like an array.

Fred
