how to make Javascript alert box display a variable from Rails controller -
i have piece of javascript codes in view file:
<script> function hint() { var str = @user.name; var name = str.tolowercase(); alert(name); } </script>
i want alert box display name of user use variable @user defined in controller. however, when click button active alert box, nothing shows up. tried current_user.name, didn't work either. how can display value of variable in alert box?
just keep this, in html file.
var str = '<%= @user.name %>';
Comments
Post a Comment