analogue40
(analogue40)
December 7, 2009, 4:39pm
1
Hi all,
Hope someone can help me out with this weird problem, I'm sure it's
something simple.
All I want to do is send the ID of the current model from the view
into the controller via a remote_function call
basiclaly I'm adding a word to a list using a check box:
check_box_tag "list_ids ", list.id, list.words.include?(word),
{ :onchange => remote_function(:url => { :controller =>
"list", :action => "add", :id => list.id }, :with => "word_id + '=' + #
{word.id}" ) }
The part which isn't working is specifically this:
:with => "word_id + '=' + #{word.id}"
If I remove it the code works but obviously I need that word.id in the
controller so I know which word to add to the list.
Thanks in advance!
Dave
Hi all,
Hope someone can help me out with this weird problem, I'm sure it's
something simple.
All I want to do is send the ID of the current model from the view
into the controller via a remote_function call
basiclaly I'm adding a word to a list using a check box:
check_box_tag "list_ids ", list.id, list.words.include?(word),
{ :onchange => remote_function(:url => { :controller =>
"list", :action => "add", :id => list.id }, :with => "word_id + '=' + #
{word.id}" ) }
First off, you could just include word_id in the :url options. If you do want to use :with then the value needs to be a fragment of javascript that evaluates to an appropriate bit of query string - I've got some examples here: http://www.spacevatican.org/2008/5/17/with-or-without-you-link_to_remote-s-mysterio
Fred
sami
(sami)
December 8, 2009, 5:22am
3
when you use remote_function the :with option actually expect
javascript code.
in your code remote_function helper is assuming "word_id + '=' + #
{word.id}" is
a javascript code.
so you can do any of the following two things
:with=> "'word_id='+document.getElementById('word_id').value" where
word_id will be the id of that element
or
you can send it to with the :url option
analogue40
(analogue40)
December 8, 2009, 12:44pm
4
Thanks for the help, I didn't realise that you can simply add any
paramter to the url call, as so:
link_to_remote 'Click', :url => {:action => 'foo', :some_param =>
42, :something_else => 'hello world'}
the link to the blog post you posted was truncated and didn't work so
I had to google for it, so I've made a short link here:
Cheers