Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在js文件中编写ruby方法_Javascript_Ruby_Ajax - Fatal编程技术网

Javascript 如何在js文件中编写ruby方法

Javascript 如何在js文件中编写ruby方法,javascript,ruby,ajax,Javascript,Ruby,Ajax,我试图在我的js(fullcalendar)日历的每个单元格中显示一个ruby方法“week_balance”,其中我有一些信息,但我不能。 我写道: dayRender:function(cell, week_balance){ $(cell).html(‘<span>’ + week_balance + ‘</span>’); }, daydrender:函数(单元格、周\余额){ $(单元格).html(“”+周余额+“”); }, 它不起作

我试图在我的js(fullcalendar)日历的每个单元格中显示一个ruby方法“week_balance”,其中我有一些信息,但我不能。 我写道:

dayRender:function(cell, week_balance){
     $(cell).html(‘<span>’ + week_balance + ‘</span>’);
     },
daydrender:函数(单元格、周\余额){
$(单元格).html(“”+周余额+“”);
},
它不起作用,为什么


谢谢。

如果您使用的是Rails框架,那么它提供了一个选项,您可以在Js文件中编写ruby代码。 为此,您需要将js文件的扩展名更改为
.js.erb
然后调用ruby函数是js方法as

dayRender:function(cell, week_balance){
   $(cell).html('<span>' + "<%= week_balance %>" + ‘</span>’);
},
daydrender:函数(单元格、周\余额){
$(单元格).html(“”+“”+“”);
},
确保在没有任何家长的情况下可以访问week_余额。否则,将其设置为类方法并使用它