Forum: Ruby on Rails how to use a $var in escape_javascript

Posted by Anush J. (anush_j)
on 2013-02-01 06:01
Hi All,

A question on using javascript within a view to render a partial. Been
struggling wit this for a bit.
I've multiple partials in my views and I want to replace them within a
specific div, how do I get this variable 'page' within the
escape_javascript and replace it with 'reviews' so I can render the
other pages (Such as specials, gallery, etc) within that div.

Thanks. Appreciate the help!
Below is the code snippet.

  <script type="text/javascript">

  $(function(load_content) {
    $("#reviews, #specials, #gallery, #location, #contact,
#about").click(function() {
      var page = this.id;
      //alert (page);

      $.pageslide.close();
      var content = "<%= escape_javascript(render(:partial =>
'reviews')) %>";
      $("#content").html(content);
    })
  })
  </script>
Posted by Frederick Cheung (Guest)
on 2013-02-01 08:23
(Received via mailing list)
On Feb 1, 5:01am, "Anush J." <li...@ruby-forum.com> wrote:
> Below is the code snippet.
You can't - the call to escape_javascript happens server side, whereas
the value of page will only be known client side, at the point where
the user clicks on something. You could load the content via ajax

Fred
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.