2017-10-14 141 views
4

我已經在nested_form_for gem的幫助下在我的rails應用程序中創建了一個嵌套窗體。我試圖將application.js轉換爲application.coffee。但我面對以下問題的nested_form_for寶石:將應用程序js轉換爲coffeescript

找不到文件 'jquery_nested_form' 型 '的應用程序/ JavaScript的'

以下是我application.coffee內容:

#= require jquery 
#= bootstrap.min.js 
#= owl.carousel.min.js 
#= require jquery_ujs 
#= require jquery-ui 
#= require jquery_nested_form 
#= require_tree ./controllers 
#= require_tree . 

任何幫助將不勝感激。提前致謝。 :)

回答

1

這裏有幾個問題。

首先,您在application.coffee的第2行和第3行中缺少一些「要求」。這些行:

#= require jquery 
#= bootstrap.min.js 
#= owl.carousel.min.js 

應該變成:

#= require jquery 
#= require bootstrap.min.js 
#= require owl.carousel.min.js 

其次,因爲nested_form創業板目前不在你的包你couldn't find file 'jquery_nested_form'錯誤是最有可能的。請確保你有這樣一行:

gem 'nested_form' 

在你的Gemfile,然後運行:

$ bundle install 

在Rails根目錄下。

最後,就像Ruby on Rails風格的一般觀點一樣,將application.js轉換爲application.coffee幾乎沒有必要或很有幫助。這個文件只是一個清單,告訴Rails將哪些javascript/coffeescript文件包含在已編譯的application.js中。由於通常不建議您向該文件添加代碼,因此將它轉換爲coffeescript似乎並不值得。將這個文件保存爲javascript並將所有代碼寫入單獨的coffeescript文件是完全正確的。從默認文件發表評論:

// This is a manifest file that'll be compiled into application.js, which will include all the files 
// listed below. 

// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
// compiled file. JavaScript code in this file should be added after the last require_* statement. 
+0

感謝您的幫助。 :) – Vishal