Ben
Ben

Reputation: 25827

How print ruby var inside haml in js area?

I am beginner in rails.

I have view that i try to print inside him @myvar inside js alert.

%script(type="text/javascript")
  alert(@myvar);

But nothing happens, What should I change?

Upvotes: 0

Views: 603

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230531

First of all, you should be using :javascript filter instead of %script definition. In javascript filter you are able to use string interpolation. Try this:

:javascript
  alert(#{@myvar});

Upvotes: 2

Related Questions