I have a Rails controller in which I am setting a instance variable -
@user_name = "Some Username"
In my .slim template I am using coffee engine to generate javascript and want to print out the user name from client-sie javascript code -
coffee:
$(document).ready ->
name = "#{@user_name}"
alert name
But this is the javascript that is being generated??
$(document).ready(function() {
var name;
name = "" + this.my_name;
alert(name);
}
How do I access controller instance variables in my CoffeeScript code??
I am tagging this as haml since I am guessing haml will have the same issue when using CoffeeScript .
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…