MaddyTheGoose
2008-Apr-11 17:06 UTC
sortable_element - issue with passing parameter with the method called from the :url => :action
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
MaddyTheGoose
2008-Apr-11 17:33 UTC
Re: sortable_element - issue with passing parameter with the method called from the :url => :action
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
On Apr 11, 1:06 pm, MaddyTheGoose
<troy.gayl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Danimal
2008-Apr-11 21:05 UTC
Re: sortable_element - issue with passing parameter with the method called from the :url => :action
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
On Apr 11, 11:33 am, MaddyTheGoose
<troy.gayl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
>
> On Apr 11, 1:06 pm, MaddyTheGoose
<troy.gayl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---