Hi all, I''m using Rails 1.1.6. In a view I have: <div id="formation_positions"> <%= render :partial => ''formation_players'' %> </div> <%= link_to ''Reset'', :action => :reset, :id => @formation %> also I have created a reset.rjs view with: page.replace_html ''formation_positions'', :partial => ''formation_players'' but doesn''t work fine, it doesn''t replace ''formation_positions'' div, instead it shows javascript code. I''ve tried page.replace instead of replace_html but I get the same result. How could I get the div replaced? Any ideas what am I doing wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
On 22.8.2006, at 13.37, Eduardo Yáñez Parareda wrote:> > Hi all, I''m using Rails 1.1.6. In a view I have: > > <div id="formation_positions"> > <%= render :partial => ''formation_players'' %> > </div> > <%= link_to ''Reset'', :action => :reset, :id => @formation %> > > also I have created a reset.rjs view with: > > page.replace_html ''formation_positions'', :partial => > ''formation_players'' > > but doesn''t work fine, it doesn''t replace ''formation_positions'' div, > instead it shows javascript code. > I''ve tried page.replace instead of replace_html but I get the same > result. > > How could I get the div replaced? Any ideas what am I doing wrong?You need to use link_to_remote to make it an Ajax call. link_to creates just a normal anchor tag. See http://api.rubyonrails.org/classes/ActionView/Helpers/ PrototypeHelper.html#M000412 Note also that you should *not* use the :update parameter in the link_to_remote call when you''re using RJS templates. If you do, you will have same kinds of problems as now. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
> You need to use link_to_remote to make it an Ajax call. link_to > creates just a normal anchor tag.But does link_to_remote go through the controller first as link_to does? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Thanks Jarkko, using link_to_remote solves the problem... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Although link_to_remote works fine, I don''t understand (I''ve already read the documentation you told me) why link_to doesn''t work. Which is the difference usinf link_to or link_to_remote? link_to does: call to the controller, then executes action, then search for a view (.rhtml, .rjs) with the same name of the action. Does not link_to_remote do the same thing? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
On 22.8.2006, at 14.27, Eduardo Yáñez Parareda wrote:> > Although link_to_remote works fine, I don''t understand (I''ve already > read the documentation you told > me) why link_to doesn''t work. Which is the difference usinf link_to or > link_to_remote?The former creates a normal, old-fashioned link: <a href="/entries/6;edit">Edit</a> The latter creates an Ajax''ed link, clicking of which will trigger an XmlHttpRequest call: <a href="/flags/new/6" id="flag_link_6" onclick="new Ajax.Request(''/flags/create/6'', {asynchronous:true, evalScripts:true}); return false;" title="Flag this content as inappropriate.">Flag</a>> > link_to does: call to the controller, then executes action, then > search > for a view (.rhtml, .rjs) with > the same name of the action. Does not link_to_remote do the same > thing?Neither of them do that. They are just helpers that produce html (see above). One creates a normal link, the other an Ajax link. You can only use RJS templates for Ajax stuff, so link_to_remote is what you''re looking for. //jarkko> > > >-- Jarkko Laine http://jlaine.net http://odesign.fi --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Thank for the answer.> Neither of them do that. They are just helpers that produce html (see > above). One creates a normal link, the other an Ajax link.Yes, I know it, I was talking about the flow produced when you click a link generated by link_to that points to a controller''s action. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
With the move to Google groups, is the spinoffs list now going to get all Ruby stuff or was this just a case of mistaken list identity? On 8/22/06, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > > On 22.8.2006, at 14.27, Eduardo Yáñez Parareda wrote: > > > > > Although link_to_remote works fine, I don''t understand (I''ve already > > read the documentation you told > > me) why link_to doesn''t work. Which is the difference usinf link_to or > > link_to_remote? > > The former creates a normal, old-fashioned link: > <a href="/entries/6;edit">Edit</a> > > The latter creates an Ajax''ed link, clicking of which will trigger an > XmlHttpRequest call: > <a href="/flags/new/6" id="flag_link_6" onclick="new > Ajax.Request(''/flags/create/6'', {asynchronous:true, > evalScripts:true}); return false;" title="Flag this content as > inappropriate.">Flag</a> > > > > > link_to does: call to the controller, then executes action, then > > search > > for a view (.rhtml, .rjs) with > > the same name of the action. Does not link_to_remote do the same > > thing? > > Neither of them do that. They are just helpers that produce html (see > above). One creates a normal link, the other an Ajax link. > > You can only use RJS templates for Ajax stuff, so link_to_remote is > what you''re looking for. > > //jarkko > > > > > > > > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
On 22.8.2006, at 16.18, Eduardo Yáñez Parareda wrote:> > Thank for the answer. > >> Neither of them do that. They are just helpers that produce html (see >> above). One creates a normal link, the other an Ajax link. > > Yes, I know it, I was talking about the flow produced when you click a > link generated by > link_to that points to a controller''s action.It doesn''t depend on that. You can write your links by hand or produce them with PHP or whatever. They''re just links. In the responding action on the server side you can detect whether it was called by XmlHttpRequest (request.xhr?), or any of the standard http methods (request.post?, get?, etc) and do whatever you want to depending on that. However, by default actions render a template with the same name as the action, be it an rhtml, rxml or rjs template (in that order IIRC). They don''t automatically detect how the action was called. In your case, there was an rjs template so it was rendered. The problem was that you had called it with a standard http get request. The browser thought that it was getting a full new html page back, and thus rendered the javascript code as text. If you had called it with a JavaScript Ajax.Request (using link_to_remote), the response would have been correctly executed as JavaScript (in the browser). But like said, this doesn''t really matter to the backend. You could use an Ajax.Updater call (using the :update attribute with link_to_remote) instead and the called action would render normal html without even knowing that the response is used inside an Ajax action. Bottom line: 1) From the server perspective, the flow is basically the same. However, 2) You *can''t* use link_to with Ajax actions because it doesn''t produce an Ajax call. But this is because of the frontend (the browser), not because of differences on the server side. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
On 22.8.2006, at 16.27, Ryan Gahl wrote:> With the move to Google groups, is the spinoffs list now going to > get all Ruby stuff or was this just a case of mistaken list identity?I would say neither :-) //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---