Crashalot
Crashalot

Reputation: 34513

Javascript block within partial not executed after partial gets rendered -- Rails 3

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.

Upvotes: 1

Views: 2010

Answers (1)

d11wtq
d11wtq

Reputation: 35298

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

Upvotes: 5

Related Questions