Possible Duplicate:
Using Ruby variable in Javascript (In App View)
is there a way to create a kind of variable in a Ruby on Rails view to use it later in a javascript tag?
I want to do something like that:
<p>
<% test=Build.where("result = 1").count(:result) %> of the builds succeeded.
</p>
<%= javascript_tag do %>
console.log(test);
<% end %>
Is there a way to do that? This is not working. Thanks in advance!
console.log(<%= test %>);The variable is in eruby context, not JS. Be sure to quote it unless it is a numeric value.