1

When rendering partials, are Javascript blocks within a partial supposed to get executed?

For instance, assume inside "_partial_exmaple.html.erb" is a call to alert().

When I render this partial inside a view, will this alert get invoked?

If so, I'm doing something wrong as the Javascript blocks contained inside a partial are not getting executed.

Inside "viewA.html.erb":

<%= render :partial => 'partialA' %>

Inside "_partialA.html.erb":

<script type="text/javascript">
    alert('hi');
</script>

The alert function to display "hi" is not getting executed.

6
  • What do you mean by "javascript blocks" exactly? What code isn't working for you? Commented Jul 2, 2011 at 0:48
  • Could you provide an example? A partial just contributes to the resulting HTML, so if the alert() is within a <script> block, it should be executed. Commented Jul 2, 2011 at 0:59
  • Yes, let me update the post with more concrete code. Sorry if it wasn't clear. Commented Jul 2, 2011 at 1:04
  • If that script is output to the page at all, it will get invoked. View the source of your page from your browser and copy/paste the results in here. Commented Jul 2, 2011 at 1:16
  • I should also add that I'm using Colorbox, the jQuery lightbox. Maybe I can post the code somewhere. Commented Jul 2, 2011 at 1:27

1 Answer 1

5

It sounds like you have a JavaScript error somewhere before this line of code, which is halting all JavaScript execution. Use your browser's JavaScript console to check for any errors.

In Chrome: View -> Developer -> JavaScript Console

Sign up to request clarification or add additional context in comments.

1 Comment

You are a smart man. Ever since Firebug changed its error count behavior, we miss more and more little errors. Often times, it'll display the error for a split second then the error count will vanish from the Firebug button. The only way to know an error occurred is to check the Console manually. Argh. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.