Hi, I have a form with a field name brand as : <input type=''text'' name=''brand''> now, using ajax I have to check if it is still available. I am trying : <%= link_to_remote "Check if it is available", :update => ''avail'', :url => ''check_brand'' %> Now how do I pass the value of the field ''brand'' as as argument to the ''check brand'' on server ? Thanks. -- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
i think you need the :with => ''#{brand}'' option. <%= link_to_remote "Check if it is available", :update => ''avail'', :url => ''check_brand'', :with => ''#{brand.id}'' %> On 2/2/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > I have a form with a field name brand as : > > <input type=''text'' name=''brand''> > > now, using ajax I have to check if it is still available. > > I am trying : > > > <%= link_to_remote "Check if it is available", > :update => ''avail'', > :url => ''check_brand'' > %> > Now how do I pass the value of the field ''brand'' as as argument to the > ''check brand'' on server ? > > Thanks. > > -- > Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
or :with => ''brand = #{brand.id}'' then you can check for params[:brand] in your controller. On 2/2/07, Jake Parsell <jake.psell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i think you need the :with => ''#{brand}'' option. > > <%= link_to_remote "Check if it is available", > :update => ''avail'', > :url => ''check_brand'', > :with => ''#{brand.id}'' > %> > On 2/2/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > Hi, > > > > I have a form with a field name brand as : > > > > <input type=''text'' name=''brand''> > > > > now, using ajax I have to check if it is still available. > > > > I am trying : > > > > > > <%= link_to_remote "Check if it is available", > > :update => ''avail'', > > :url => ''check_brand'' > > %> > > Now how do I pass the value of the field ''brand'' as as argument to the > > ''check brand'' on server ? > > > > Thanks. > > > > -- > > Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
Put the input into a form. Then either submit the form with form_remote_tag etc, or... Jake Parsell wrote:> i think you need the :with => ''#{brand}'' option. > > <%= link_to_remote "Check if it is available", > :update => ''avail'', > :url => ''check_brand'', > :with => ''#{brand.id}'' > %>The target of :with is a JavaScript string that will insert into the link''s parameter list. The above won''t work for a list of reasons. (Sorry, Jake, but the newbs need the list, to learn what to avoid!) Ruby won''t interpret single-quoted strings ''#{}'' as anything but strings containing literal hatches, braces, etc. That needed double quotes "" to invoke the sting #{embedding} system. Next, if brand.id existed, it would resolve at Ruby time, not at Ajax time, after a user changes the field. There might be some way to with=> a JavaScript string that fetches the field value into a named parameter, but I would just go with with => ''Form.serialize("my_form_id")''. -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Aaaaand... Jake Parsell wrote:> or :with => ''brand = #{brand.id}''That becomes an URI query segment, so the = can''t have spaces around it! :-) -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
This is what is in controller : def check_brand brand=params[''brand''] textbrand = Textbrand.look_by_textbrand(brand) if textbrand.nil? # valid render :text=> ''It is available.'' else render :text=> ''It is already taken.'' end end and this is in view : <tr> <td height="26" colspan="3" valign="top"> <input onfocus="this.value='''';" id=''brand'' maxlentgh=15 name="brand" type="text" value="(max 15 chars)" class="c11"> </td> <td colspan="3"/> </tr> <tr> <td height="24" colspan="3" valign="top"> <%= link_to_remote "Check if it is available", :update => ''avail'', :url => ''check_brand'', :with => ''brand=#{brand.id}'' %> </td> <td colspan="3"/> </tr> <tr> <td height="3"/> <td colspan="5"/> </tr> <tr> <td id=''avail'' width="38%" rowspan="2" colspan="3" class="c16"></td> <td height="16"/> <td colspan="2"/> </tr> And it is not working. Any help is greatly appreciated. Jake Parsell wrote:> i think you need the :with => ''#{brand}'' option. > > <%= link_to_remote "Check if it is available", > :update => ''avail'', > :url => ''check_brand'', > :with => ''#{brand.id}'' > %>-- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
Still, none of the above ideas work. The field is in a form but I don''t need to submit the form now. Just check availability and go ahead with the rest of the form. -- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
<%= link_to_remote ''check'' , :update => ''avail'', :url => {:action => ''check_brand''} , :with =>"''brand=try''" %> This works with the hardcoded value of try. But how do I put the value of field ''brand''. -- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
Rm Rm wrote:> <%= link_to_remote ''check'' , > :update => ''avail'', > :url => {:action => ''check_brand''} , > :with =>"''brand=try''" > %> > > This works with the hardcoded value of try. But how do I put the value > of field ''brand''.Did you read my first post? -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rm Rm wrote:> The field is in a form but I don''t need to > submit the form now. Just check availability > and go ahead with the rest of the form.I haven''t seen the controller / view code you''re using to render the form but, based on what you''ve posted, I assume you''re iterating through a collection of records and rendering a table row for each one using something like @brands.each do |brand| ... end If that''s the case, then in the view code you''d use ... <%= link_to_remote("Check if it is available", :url => {:action => ''check_brand'', :id => brand.id}, :update => ''avail'') %> and in the check_brand action you''ll need to change to brand = params[:id] Note that this will get you to the point where the code in the controller gets executed. However, the update in the browser will not happen correctly if my assumption above about iterating through a collection is correct, given the code you''ve shown so far. DOM elements have to have unique IDs. It looks to me like each row in your table is going to have a <td> with an id=''avail''. Another source of potential difficulty will be your use of tables for layout. I think the <td> can be updated, but can''t remember for sure. I''ve quit using tables because of all the hacks and workarounds needed to use them with ajax. hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes, I did try that. But it does not work. -- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
Bill, I am not going through a loop , so update is not a problem. But I am getting errorr brand not found . undefined local variable or method `brand'' for #<#<Class:0x6f47eb8>:0x6f47e90> Extracted source (around line #234): 231: 232: <%= link_to_remote ''check'' , 233: :update => ''avail'', 234: :url => {:action => ''check_brand'', :id => brand.id} 235: 236: %> 237: My view has: <input onfocus="this.value='''';" id=''brand'' maxlentgh=15 name="brand" type="text" value="(max 15 chars)" class="c11"> -- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
Rm Rm wrote:> 231: > 232: <%= link_to_remote ''check'' , > 233: :update => ''avail'', > 234: :url => {:action => ''check_brand'' }:with => ''Form.serialize("my_form")''> 236: %>That won''t submit the form, it will pass all its field values to your action. -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I don''t want form to be submited, I just want to get the value of field ''brand'' in action to validate it. Phlip wrote:> Rm Rm wrote: > >> 231: >> 232: <%= link_to_remote ''check'' , >> 233: :update => ''avail'', >> 234: :url => {:action => ''check_brand'' } > > :with => ''Form.serialize("my_form")'' > >> 236: %> > > That won''t submit the form, it will pass all its field values to your > action. > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!-- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---
Rm Rm wrote:> I don''t want form to be submited, I just want to get the value of field > ''brand'' in action to validate it.> > :with => ''Form.serialize("my_form")''> > That won''t submit the form, it will pass all its field values to your > > action.Do you see where I wrote "That won''t submit the form"? -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rm Rm wrote:> I am not going through a loop , so update is > not a problem. But I am getting errorr brand > not found .I need to see the controller code you''re using to ''feed'' the initial form build to help further. Two other things. 1) The view code that constructs the form. You say this is all happening within a form, but the view code you posted earlier had no form or submit tags. 2) The name of the person with whom I''m conversing. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<%= link_to_remote ''check'' , :update => ''avail'', :url => {:action => ''check_brand''}, :with => "''brand=''+escape($F(''brand''))" %> This worked !! Thanks to all of you . And a big thanks to ''Ajax on Rails'' by Scott Raymond which actually had an example similar to my problem. -- Posted via http://www.ruby-forum.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-/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 -~----------~----~----~----~------~----~------~--~---