0

This one is long to explain but basically my controller is built and expects an array in params[:order_items], so I've tried it like this:

<%= hidden_field_tag "order_items", @order[:order_items_ids] %>

but I get the ids concatenated

<input id="gig_items" name="gig_items" type="hidden" value="2300124946">

So, How do I send and array in one of the params keys using just html (without js)?

2
  • sorry, I'm afraid of monsters... Commented Jan 18, 2013 at 12:05
  • ...but try: <%= hidden_field_tag "order_items", @order[:order_items_ids].to_json %> Commented Jan 18, 2013 at 12:06

2 Answers 2

5

You can post it in a string joined by ',' like:

<%= hidden_field_tag "order_items", @order[:order_items_ids].join(",") %>

then split it in your controller. But if you really want it in an array. You can also do it like this:

<%@order[:order_items_ids].each do |oid|%>
    <%= hidden_field_tag "order_items[]", oid %>
<%end%>
Sign up to request clarification or add additional context in comments.

1 Comment

nice and simple! completly saved my a@@! 10x!
2

I would do it but there's maybe a better solution with html:

<% @order.order_items_ids.each do |o| %>
     <input id="order_items" name="order_items[]" type="hidden" value="<%= o %>" />
<% end %>

EDIT: Just to say, for order items, I would put it in session if I were you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.