Hi All, I want to refresh a partial onClick, onClick i am making ajax call and getting the data but i am unable to refresh the partial. here is the code IN views: home.html.erb $(document).ready(function() { var currentCellText; $(".inline").click(function() { currentCellText = $(this).text(); $.ajax({ type: ''GET'', dataType: "json", url:''/test'', async: false, data:{ foo1:currentCellText }, dataType: "json", success:function(data){ alert(data); $("ul#mymenu ul#mixed").html(data); }, error:function(data){ alert("Error"); } }); }); }); <body> <%= render(:partial => "partial", :object => @object) %> </body> contoller action def some_action @object = Class.where(some_condition) render :home do |page| page["#myMenu #mixed"].replace_html :partial => "event" :object=> @object end end partial _partial.html.erb <ul id="myMenu" class="contextMenu"> <ul id="mixed"> <li><%="My Events"%> <ul> <li><span> <%@object.each do |k|%> <li><%=k%></li> <%end%> </span></li> </ul> </li> </ul> how can I refresh this partial onclick. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Hi, I would do it the following way: 1. Create an AJAX call with $.getScript() 2. Use it to call "some_action" in the controller 3. In the controller create a JS view (for example ''show.js.erb'') and put it into the respond_to block 4. In your JS view, write some javascript to update the dom on your current page. Use the "escape_javascript" function of the view to render the partial. (Example: $(''.some-div'').html(''<%= escape_javascript(render ''my_cool_partial'') %>''); ) The $.getScript() function will request the JS view and execute it''s code. Hope that helps! Hias Am Mittwoch, 6. März 2013 18:09:49 UTC+13 schrieb Ruby-Forum.com User:> > Hi All, > > I want to refresh a partial onClick, onClick i am making ajax call > and getting the data but i am unable to refresh the partial. here is the > code > > IN views: home.html.erb > $(document).ready(function() { > var currentCellText; > $(".inline").click(function() { > currentCellText = $(this).text(); > $.ajax({ > type: ''GET'', > dataType: "json", > url:''/test'', > async: false, > data:{ foo1:currentCellText > }, > dataType: "json", > success:function(data){ > alert(data); > $("ul#mymenu ul#mixed").html(data); > }, > error:function(data){ > alert("Error"); > } > }); > }); > }); > <body> > <%= render(:partial => "partial", :object => @object) %> > </body> > > contoller action > > def some_action > > @object = Class.where(some_condition) > render :home do |page| > page["#myMenu #mixed"].replace_html :partial => "event" > :object=> @object > end > end > > partial _partial.html.erb > > <ul id="myMenu" class="contextMenu"> > <ul id="mixed"> > <li><%="My Events"%> > <ul> > <li><span> > <%@object.each do |k|%> > <li><%=k%></li> > <%end%> > </span></li> > </ul> > </li> > > </ul> > > > how can I refresh this partial onclick. > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/qQNxS7R4SAoJ. For more options, visit https://groups.google.com/groups/opt_out.
Praveen BK
2013-Mar-07 06:24 UTC
Re: Refresh a partial onClick using ajax call in rails 3.x
Thank you for your guidance but i am stuck here i am unable to use getScript properly After executing my code In views home.html.erb: $(document).ready( function() { $(".inline").click(function() { currentCellText = $(this).text(); $(''.dynamic'').load(''/test'',{foo1: currentCellText}); }); }); routes.rb: match ''/test'', to: ''sessions#some_action'' controller code: def some_action @object = Class.where(some_condition) respond_to do |format| format.js end some_action.erb $(".dynamic").html("<%= escape_javascript(render(:partial => ''partial'', :locals => {:object => @object})).html_safe %>"); my partail _partial.html.erb <ul id="myMenu" class="contextMenu"> <ul id="mixed"> <li><%="My Events"%> <ul> <li><span> <%@object.each do |k|%> <li><%=k%></li> <%end%> </span></li> </ul> </li> </ul> Present output $(".dynamic").html(" \n \n My Events\n \n \n <\/span><\/li>\n <\/ul>\n <\/li>\n Please guide me how to use getScript(), is there any example for this. And onClick i have to refresh my partial with @object values and display it in html. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.