我正在尝试从 Rails 3.2 应用程序中的控制器调用 javascript 函数(实际上是咖啡脚本)。
我收到一个Render and/or redirect were called multiple times in this action
错误。
我的代码如下所示:
#Model.controller
def index
@models = Model.all
my_action if current_user.name == "Bob" #or some other general conditional
...and some stuff
respond_to do |format|
format.html
format.js #this is needed to handle ajaxified pagination
end
end
def my_action
respond_to do |format|
format.js { render :js => "my_function();" } #this is the second time format.js has been called in this controller!
end
end
#functions.js.coffee.erb
window.my_function = ->
i = xy
return something_amazing
从控制器调用 js 函数的正确方法是什么?