Forum: Ruby on Rails hidden_field_tag flattens my array for value

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Taylor S. (Guest)
on 2009-01-11 00:35
ERB:
<%= hidden_field_tag('users_ids', @users.collect(&:id))%>

OUTPUT:
  <input id="users_ids" name="users_ids" type="hidden"
value="127101520242526273035394142555772737479838593101104117121127128132133136143149162169170177181184187190198200203205206223226227228235238245246250254255260264265269270277279286288292298306310312314316323327329333335338345362365366367380384385386397399406408410415420423427429430438441442444446447452461466468473477483484492493499503506518519520531533536537539548553556560574581585586588602605614616623627630631633641644645647649650653655662666669670671680681683687689691693698702706712719720727746750753758759761766768771773774777778779780781782783786787789793805811813816817829830831835842847848851854855862863864869874877882886896899904908909914919920922933934945950959966967968973976977979981985986989991994996997"
/>


I want to grab an array of user ids and then do something with them, but
hidden_form_tag is flattening my array.  I've tried various ways of
putting an array into h_f_t and it always flattens it.  How can I
preserve the structure of my array?
Maurício L. (Guest)
on 2009-01-11 00:49
(Received via mailing list)
Try this:

<% for user in @users %>
    <%= hidden_field_tag "user_id[]", user.id %>
<% end %>

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



On Sat, Jan 10, 2009 at 8:35 PM, Taylor S.
Taylor S. (Guest)
on 2009-01-13 00:53
Maurício Linhares wrote:
> Try this:
>
> <% for user in @users %>
>     <%= hidden_field_tag "user_id[]", user.id %>
> <% end %>
>

This worked perfectly.  Thank you.
This topic is locked and can not be replied to.