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
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
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