(Original post: http://stackoverflow.com/questions/14569721/rails-parameters-get-lost-because-of-jquery-link, unfortunately no response) I saw this Railscast ( http://railscasts.com/episodes/240-search-sort-paginate-with-ajax) the other day and wanted to use the techniques for an application of mine. I have a page with elements on it and I want to sort them by values and select them by tags. Also I tried to combine it with the nice jQuery links. In the view I have some of the links: %nav#sort %span= link_to t(''name''), params.merge(:sort => ''name'') %span= link_to t(''value''), params.merge(:sort => ''value'')%nav#tag %span= link_to t(''all''), params.merge(:tag => ''all'') %span= link_to t(''basic''), params.merge(:tag => ''basic'') And this is the jQuery in the application.js calling to render the main part of the page: $(function() { $("#sort span a, #tag span a").on("click", function() { $.getScript(this.href); return false; });}); The defaults are ''name'' for sort and ''basic'' for tag. They are set in methods within the controller and model for not being redundant. The linking itself works perfectly fine and the jQuery itself, too. However if I add the jQuery to the linking, the parameters will not get passed and so can not be merged. I guess when the page is reloaded there is no parameter set and jQuery does not pass the first one I click on. Though somehow in Ryan Bates'' Railscast it does work and even if I download it, it works just fine. Does anybody know what the mistake might be? I already had to change it from ".live("click", function()" to ".onlive("click", function()" for the new jQuery 1.9.0. Is it because of the jQuery version (1.4.3 in the Railscast and 1.9.0 now)? -- 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/-/ECFBHu8W584J. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-Feb-12 20:20 UTC
Re: Rails parameters get lost because of jQuery link
On Tuesday, February 12, 2013 1:57:58 PM UTC, Andreas Fritz wrote:> > The defaults are ''name'' for sort and ''basic'' for tag. They are set in > methods within the controller and model for not being redundant. > > The linking itself works perfectly fine and the jQuery itself, too. > However if I add the jQuery to the linking, the parameters will not get > passed and so can not be merged. I guess when the page is reloaded there is > no parameter set and jQuery does not pass the first one I click on. Though > somehow in Ryan Bates'' Railscast it does work and even if I download it, it > works just fine. Does anybody know what the mistake might be? >The mistake is that your links aren''t updated because you are only re-rendering your content section. You could re-render a large part of the page, including the links. The railscast takes a slightly different approach - he users extra hidden fields in the bits of the page that are re-rendered so that even though the link doesn''t have the previously selected order/sort in it, it can be retrieved from the form Fred -- 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/-/bqy1lsvWvSAJ. For more options, visit https://groups.google.com/groups/opt_out.
Wow, I never would have thought of that. Thank you so much, you made my day =). Am Dienstag, 12. Februar 2013 21:20:33 UTC+1 schrieb Frederick Cheung:> > > > On Tuesday, February 12, 2013 1:57:58 PM UTC, Andreas Fritz wrote: >> >> The defaults are ''name'' for sort and ''basic'' for tag. They are set in >> methods within the controller and model for not being redundant. >> >> The linking itself works perfectly fine and the jQuery itself, too. >> However if I add the jQuery to the linking, the parameters will not get >> passed and so can not be merged. I guess when the page is reloaded there is >> no parameter set and jQuery does not pass the first one I click on. Though >> somehow in Ryan Bates'' Railscast it does work and even if I download it, it >> works just fine. Does anybody know what the mistake might be? >> > > The mistake is that your links aren''t updated because you are only > re-rendering your content section. You could re-render a large part of the > page, including the links. The railscast takes a slightly different > approach - he users extra hidden fields in the bits of the page that are > re-rendered so that even though the link doesn''t have the previously > selected order/sort in it, it can be retrieved from the form > > Fred >-- 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/-/sNYI2Cn9G_wJ. For more options, visit https://groups.google.com/groups/opt_out.