[英]How do I use CoffeeScript in Rails?
在我的控制器的create
操作中,我有以下內容:
def create
@article = Article.find(params[:id])
respond_to do |format|
if @comment.save
format.js { render 'success.js' }
else
format.js { render 'failed.js' }
end
end
end
在我的app/views/comments/failed.js.coffee
,我有:
alert 'Write smth!' if $("#comments_error").length == 0
我收到以下錯誤:
ActionView::MissingTemplate (Missing template comments/failed,
inherited_resources/base/failed, application/failed with
{:locale=>[:en, :en],
:formats=>[:js, :html],
:handlers=>[:haml, :builder, :erb]})
我究竟做錯了什么?
在撰寫本文時,Rails不支持使用咖啡腳本文件進行響應。 然而,這將發生變化。
同時在你的Gemfile中添加:
gem 'coffeebeans'
然后命名你的觀點action.js.coffee
作為額外的獎勵,文件將首先通過erb,即使它未在文件名中聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.