How to pass an array IN via GET?

Howdy.

I’m not sure what the right way to do this is. I basically need to
pass an array in via GET to my controller action.

For a little background, here’s what’s going on from the user’s
perspective:

User clicks some checkboxes in my YUI DataTable, thereby marking some
rows.
User then clicks something that causes me to gather up a list of the
selected items, then set those as a new request for another DataTable.

My controller gets these request params, builds a conditions list, and
fetches records from my model.

For example, my URL would be something like this:
/my_controller/my_action?group=users&limits=dog,cat,bird

Then in my_action(), I want to use params[:limits] in conjunction
with
my_model.find(:all, :conditions => { [animal in (?)],
params[:limits] } )

(My syntax may be off in my example, but hopefully my goal is clear.)

Thanks!

Sure, it’s easy. Just append your parameter with empty brackets ([]):

<%= check_box_tag ‘limit[]’, ‘dog’ %>
<%= check_box_tag ‘limit[]’, ‘cat’ %>

Your URL will end up looking like:

/my_controller/my_action?group=users&limits[]=dog&limits[]=cat&limits[]=bird

And params[:limit] will be an array.

Brandon

On Mon, May 19, 2008 at 3:17 AM, michael_teter [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs