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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2009-Dec-07 18:30 UTC
Re: remote_function - how to include a id of current model
On 7 Dec 2009, at 16:39, analogue40 wrote:> 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> 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 > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Dec 7, 11:39 pm, analogue40 <analogu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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! > > Davethanks Syed Samiuzzaman software Engineer Code71 Inc ( www.code71.com) product: www.scrumpad.com blog: samiuzzaman.blogspot.com -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
analogue40
2009-Dec-08 12:44 UTC
Re: remote_function - how to include a id of current model
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: http://bit.ly/link_to_remote Cheers On Dec 8, 2:30 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7 Dec 2009, at 16:39, analogue40 wrote: > > > 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_rem... > > Fred > > > 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 > > > -- > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.