in AJAX, there is responseText, responseBody, responseXML, responseStream, so I don''t know what I can use to get instance variable return from ajax on ruby.. who can tell me, how can I do. Thanks!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Daniel Waite
2007-Oct-19 22:06 UTC
Re: How can I get instance variable return from ajax on ruby
OnRails wrote:> in AJAX, there is responseText, responseBody, responseXML, > responseStream, > so I don''t know what I can use to get instance variable return from > ajax on ruby..That depends on what you want to do with your instance variable. The easiest way is probably to use an RJS template. But first, some perspective... See, the question isn''t really "how can I get at this instance variable," it''s, what do I do with the data given to me from my Ajax request? And the answer to that question depends on what format the data is in and what JavaScript framework you''re using. If you''re using Prototype, try using an RJS template first. Here''s an example (from memory, so it might not be 100% accurate): def my_action @my_var = MyObject.find(:first) render :update do |page| page.replace_html(''some_dom_id'', @my_var.some_attribute) end end The render :update directive tells your application to render JavaScript to be executed by the browser. RJS stands for Ruby JavaScript (I think) and is basically like writing JavaScript with Ruby code. You have access to a lot of Prototype''s functionality from within these templates, and you don''t have to write any JavaScript. See the doc on Rails'' JavaScript generator: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html Good luck! -- 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 -~----------~----~----~----~------~----~------~--~---
OnRails
2007-Oct-19 23:53 UTC
Re: How can I get instance variable return from ajax on ruby
Thanks Daniel. in my case, I just want to get @searchresult. In controller: search_controller .. def index ..some codes. end def search @searchresult=Search.find(:all) some other codes. end in views: search.rthml <div id="a"> <select id="a1"><option value="aa">aa <option value="bb">bb <option value="cc ">cc </select> <div id="result"> here just display @searchresult <====juse display @searchresult (1) </div> </div> when I used AJAX, that means I changed selected, I got all the changed content, include index and search, displayed (1) so I don''t know what I can use to get instance variable return from ajax. and I don''t want to make XML file for this case. Just only want to get @searchresult to change view... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---