# Updating postitions in an acts as list model, with tet field

**URL:** <https://www.ruby-forum.com/t/updating-postitions-in-an-acts-as-list-model-with-tet-field/115031>\
**Category:** Rails\
**Created:** [September 19, 2007, 9:46pm UTC](https://www.ruby-forum.com/t/updating-postitions-in-an-acts-as-list-model-with-tet-field/115031 "2007-09-19T21:46:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 19, 2007, 9:46pm UTC](https://www.ruby-forum.com/t/updating-postitions-in-an-acts-as-list-model-with-tet-field/115031/1 "2007-09-19T21:46:14Z")

</div>

Hey all.

I’m trying to copy this example I found, which I’m assuming no longer  
works… that or I’m stupid… I want to have the position for each  
“row” show up ina box, with a “update position” button that submits  
the form, and updates the position… in retropect I shuld have used  
the Draggable effect in Scriptaculous, it would have been faster.  
Anyway, now I’m wondering how I would do this… Any help would be  
great.

I get a parameter that holds everything I want

{“commit”=\>“Update Positions”,  
“rate\_group\_additional\_rate”=\>{“1488”=\>{“position”=\>“6”},  
“948”=\>{“position”=\>“1”}, “949”=\>{“position”=\>“2”},  
“1396”=\>{“position”=\>“5”}, “950”=\>{“position”=\>“3”},  
“951”=\>{“position”=\>“4”}}}

where rate\_group\_additional\_rate is the model’s position I want to  
upgrade.

* * *

[http://lists.rubyonrails.org/pipermail/rails/2005-February/002489.html](http://lists.rubyonrails.org/pipermail/rails/2005-February/002489.html)

class PurchaseOrdersController \< ApplicationController  
def new  
@purchase\_order = PurchaseOrder.new(@params[‘purchase\_order’])  
@order\_items = @purchase\_order.items  
end  
end

Then, in your view (new.rhtml, for example):

\<% @order\_items.each do |@order\_item| %\>  
\<%= text\_field “order\_item[]”, “name” %\>  
\<%= text\_field “order\_item[]”, “price” %\>  
… etc …  
\<% end %\>

The trailing square brackets after the object name (order\_item[])  
tells Rails to automatically add the index (“id” field) of that  
order\_item to the form element (a text field in this case). So you’ll  
get HTML like this, for example:

\<input type=“text” name=“order\_item[33][name]” … \>  
\<input type=“text” name=“order\_item[33][price]” … \>

\<input type=“text” name=“order\_item[39][name]” … \>  
\<input type=“text” name=“order\_item[39][price]” … \>

This is especially handy for the new 0.9.5 “update” method which will  
take a hash of hashes and update the correct IDs:

def create  
OrderItem.update @params[‘order\_item’] #Updates both items 33 and  
39  
end

* * *

The first part works great, I can’t seem to get my head around how to  
update all the “Order Items” in this case. When I type the exmple as  
it is below, I get a “wrong number of arguments (1 for 2)” error.
