# Sortable\_element - issue with passing parameter with the method called from the :url =\> :action

**URL:** <https://www.ruby-forum.com/t/sortable-element-issue-with-passing-parameter-with-the-method-called-from-the-url-action/134529>\
**Category:** Rails\
**Created:** [April 11, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/sortable-element-issue-with-passing-parameter-with-the-method-called-from-the-url-action/134529 "2008-04-11T19:07:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaddyTheGoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@MaddyTheGoose](https://www.ruby-forum.com/u/MaddyTheGoose)\
**Post date:** [April 11, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/sortable-element-issue-with-passing-parameter-with-the-method-called-from-the-url-action/134529/1 "2008-04-11T19:07:43Z")

</div>

Is it possible to pass a parameter with the method call attached to  
the :action of sortable\_element? I’ve put together the code below  
which doesn’t work but it demonstrates the desired behavior.

# in the view (well, in the helper really but in a method that’s

called from the view).  
container\_ids\_containing\_items.each do |container\_id|  
output += sortable\_element(  
[“items\_contained\_by\_container\_id\_”, container\_id].join,  
:constraint =\> false,  
:handle =\> “gearItemValueTitle”,  
:containment =\> container\_ids\_containing\_items.map { |n|  
[“items\_contained\_by\_container\_id\_”, n].join},  
:scroll =\> “window”,  
:url =\> {:action =\>  
“update\_contained\_items\_positions(”#{container\_id}")"})

# in the controller

def update\_contained\_items\_positions(container\_id)  
# … - perform save  
end

---

<div class="post-metadata">

**Author:** ![MaddyTheGoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@MaddyTheGoose](https://www.ruby-forum.com/u/MaddyTheGoose)\
**Post date:** [April 11, 2008, 7:34pm UTC](https://www.ruby-forum.com/t/sortable-element-issue-with-passing-parameter-with-the-method-called-from-the-url-action/134529/2 "2008-04-11T19:34:11Z")

</div>

just noticed an issue with the quoting of the paramter. I’ve fixed it  
but it still doesn’t work, here is the updated sample:

```
container_ids_containing_items.each do |container_id|
  output += sortable_element(
    ["items_contained_by_container_id_", container_id].join,
    :constraint => false,
    :handle => "gearItemValueTitle",
    :containment => container_ids_containing_items.map { |n|

```

[“items\_contained\_by\_container\_id\_”, n].join},  
:scroll =\> “window”,  
:url =\> {:action =\>  
“update\_contained\_items\_positions(#{container\_id})”}) # \<---- made  
change to the quoting of container\_id

---

<div class="post-metadata">

**Author:** ![MaddyTheGoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@MaddyTheGoose](https://www.ruby-forum.com/u/MaddyTheGoose)\
**Post date:** [April 11, 2008, 11:12pm UTC](https://www.ruby-forum.com/t/sortable-element-issue-with-passing-parameter-with-the-method-called-from-the-url-action/134529/3 "2008-04-11T23:12:46Z")

</div>

Maddy,

Instead of passing a parameter like that in the action, pass it as a  
separate has value. I.e.:

:url =\> {:action =\> “update\_contained\_items\_positions”, :id =\>  
container\_id }

Then, in the controller action, just use params[:id] to reference the  
id.

I don’t know that action methods can include arguments as I don’t know  
how the routing would handle that.

See if that helps.

-Danimal
