Forum: Ruby on Rails Can I use erb code inside a .js file?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E336df27d1ef1dbcf28d2df9dffc0c45?d=identicon&s=25 Medha Kulkarni (Guest)
on 2007-01-02 16:21
(Received via mailing list)
Hi all,

Can I have a ruby code inside a java script function written in .js
When I tried it, i got an error.
e.g. consider following function inside myscript.js file

function sayHi
    alert('HI <%=name%>');

But this works if I have above function in a rhtml file inside <script>

Any inputs in this regard will be really helpful.

Thanks and Regards,
This topic is locked and can not be replied to.