在RoR中将变量值注入javascript和HAML [英] Injecting variable values into javascript and HAML in RoR
本文介绍了在RoR中将变量值注入javascript和HAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下使用ZenDesk的功能。我想将current_user详细信息注入表单,如下所示。 (这是我的html.haml模板)。但是我无法弄清楚如何使这项工作。
I have the following function for using ZenDesk. I'd like to inject my current_user details into the form as follows. (this is my from html.haml template). However I cannot figure out how to make this work.
:javascript
if (typeof(Zenbox) !== "undefined") {
Zenbox.init({
dropboxID: "xxxxx",
url: "xxxxx.zendesk.com",
tabID: "support",
tabColor: "black",
tabPosition: "Left",
requester_name: =current_user ? "#{current_user.first_name} #{current_user.last_name}" : "" ,
requester_email: =current_user ? "#{current_user.email}" : "" ,
hide_tab: true
});
}
简而言之,如何将rails变量注入haml中的:javascript元素。
In short, how does one inject rails variables into a :javascript element in haml.
推荐答案
这应该有效。将所有内联ruby放入#{}
:
This should work ie. put all inline ruby inside of #{}
:
requester_name: "#{current_user.first_name + ' ' + current_user.last_name if current_user}",
requester_email: "#{current_user.email if current_user}",
这篇关于在RoR中将变量值注入javascript和HAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文