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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -