Thanks for the quick response. I could use a switch/case structure to handle the
$("#services").html("<%= escape_javascript(render(:partial => "a" )) %>").show() call as there are only 6 partials I need. I have 6 links on the page that only vary by the "section" value. I still need some guidance on pulling out the value of the "section" attribute from the <a> DOM element. Any idea on that part? Dave On Sep 10, 9:37 am, Frederick Cheung <frederick.che...@gmail.com> wrote: > On Sep 10, 12:18 pm, dwormuth <dworm...@post.harvard.edu> wrote: > > > > > > > I'm having trouble wrapping my head around the proper syntax to have > > jQuery (in an .js file) grab an HTML attribute and use the value of > > that attribute to load a partial. > > > HTML fragment: > > <a href="/toggle" data-remote="true" section="training"> > > > jQuery string (now setting a static partial, I need this to be > > dynamic) > > $("#services").html("<%= escape_javascript(render(:partial => > > "operations" )) %>").show() > > > I want the value of "section" as that corresponds to the name of the > > partial. I've tried to look at this in Firebug, but I'm not able to > > set the proper breakpoint so I can see the context when the jQuery > > string is evaluated. > > > What I want is something like: > > > foo = $(this).data("section") > > > $("#services").html("<%= escape_javascript(render(:partial => foo )) > > %>").show() > > > or > > > $("#services").html("<%= escape_javascript(render(:partial => $ > > (this).data("section") )) %>").show() > > This isn't possible. Whatever is in your <%= %> bits is evaluated when > the response is served by your browser. It can't use information that > will only come into existence once the user has started to interact > with the page in the browser. You'd either need to have all those > partials hidden somewhere on the page so that the js can find them or > make an Ajax request once you know which partial is needed. > > Fred > > > > > Thank you for you time -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.