因此,我在一些 javascript 响应程序中搞乱了一些操作。所以,例如,
def create
#code omitted
respond_to do |format|
if @post.save
format.html { redirect_to discussion_posts_path(@post.discussion), notice: 'Post was successfully created.' }
format.js
else
format.html { render :action => "new" }
end
end
end
#create.js.erb
$("#discussion_posts_table").append("<%= escape_javascript(render(@post)) %>");
$("#post_body").val("");
现在假设我想将这些javascript函数转换为Coffeescript(撇开它几乎没有任何收获的事实不谈),如果我将文件更改为create.js.coffee.erb
它停止工作。在 UJS 中使用咖啡脚本的正确方法是什么?
作为记录,我coffee-rails
在我的 Gemfile 中有,并且在资产管道中使用咖啡脚本。