admin管理员组文章数量:1277900
I have the following variable in my controller:
class MyController < ApplicationController
def my_method
@status = "status"
end
end
In my haml
view, I tried following, but it doesn't work (since it's using the default .erb syntax):
#app/views/mycontroller/me_method.html.haml
:javascript
alert(<%=raw @status %>)
How can I use the @status
variable inside my inline JavaScript?
I have the following variable in my controller:
class MyController < ApplicationController
def my_method
@status = "status"
end
end
In my haml
view, I tried following, but it doesn't work (since it's using the default .erb syntax):
#app/views/mycontroller/me_method.html.haml
:javascript
alert(<%=raw @status %>)
How can I use the @status
variable inside my inline JavaScript?
-
Except the possible typo
my_method
withme_method
I can't find anything wrong. – Billy Chan Commented Feb 17, 2014 at 9:35
3 Answers
Reset to default 6You can use the simple "#{}" interpolation tags to use ruby variables with HAML.
Your code:
:javascript
alert(<%=raw @status %>)
Possible Solution:
:javascript
alert("#{@status}")
Use the normal string interpolation syntax (#{}
).
#app/views/mycontroller/me_method.html.haml
:javascript
alert(#{raw @status})
See also this previous SO question:
Inline ruby in :javascript haml tag?
Just like you would do in a ruby string :
:javascript
alert("#{raw @status}")
本文标签: How can I use a Ruby variable in an inline JavaScript in hamlStack Overflow
版权声明:本文标题:How can I use a Ruby variable in an inline JavaScript in haml? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741235067a2362848.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论