Reputation: 8297
I am using the partial helper module mentioned in the Sinatra documentation. When I add JavaScript in the partial, it is placed in the HTML output exactly where I put it. But there is a new js/jsquery--1.7.js/eval/seq/[1](array)
in the scripts block (I can see this from firebug), which is equivalent to what I put in the partials file, and this is getting evaluated as well, and as a result the events are getting triggered again.
Suppose you put an alert('helloworld') in the partial -- it would get triggered twice. What is happening and how can this be avoided?
Upvotes: 3
Views: 565
Reputation: 25091
This answer could be significantly better, but you'd have to post some sample code on how you are using the partial (as requested 4 days ago by @summea).
Your question sounds like you are seeing the JavaScript code you placed in the partial rendered twice to the page, once in the html where you put it and once in Firebug ("js/jsquery-1.7.js/eval/seq/1").
Make sure you are only rendering that particular partial once to the page, or your JavaScript will fire more than once (as it's on the page more than once).
In other words:
<%= render "myPartialWithJavaScript" %>
<h1>My Page</h1>
<p>Welcome to my page!</p>
is fine and:
<%= render "myPartialWithJavaScript" %>
<h1>My Page</h1>
<p>Welcome to my page!</p>
<%= render "myPartialWithJavaScript" %>
will cause your JavaScript to be executed more than once.
Upvotes: 2