2017-08-15 80 views
2

我正在將我的rails 4.2.0應用升級到5.1.2,這很順利。我曾使用Angular 1.x來選擇性地增強我的rails應用程序頁面。我的rails視圖在HAML中。這裏是一個在4.2.0精加載頁面的摘要,但沒有在5.1.2:從rails升級到rails 5.1.2 4.20中斷角集成

.well{"ng-app" => "billing", "ng-controller" => "BillableCtrl"} 
    = simple_form_for @billable do |f| 
    .row 
     .col-md-4 

這將加載在該視圖的角度罰款。不過,當我嘗試在Rails 5.1.2中加載時,我在我的JavaScript控制檯中得到了以下堆棧跟蹤。

Uncaught SyntaxError: Unexpected token & angular.self-26d045c60a96c782aa8ef9f5709b1b4fd1ec8578bc37ec2c6c2b9c4370f4bac0.js?body=1:64 Uncaught Error: [$injector:modulerr] Failed to instantiate module billing due to: Error: [$injector:nomod] Module 'billing' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

我在rails 5.1.2升級中使用ngannotate-rails version 1.2.2。 rails 4.2.0版本中使用的ngannotate-rails版本是0.15.4。

有沒有其他人遇到過這個問題?有什麼選擇要調查?

回答

0

事實證明,這不是一個角度問題,而是一個Rails to Javascript消息傳遞問題。在我的一個javascript函數中查看以下代碼行:

$ scope.billable_item = #{@billable.to_json};

根據我的經驗,直到Rails 4.2.0,這是將Rails數據傳遞到JavaScript的標準方式。但是,由於某些原因,我還不明白,它是壞的。這導致Angular發出非常混亂的消息。我一直在使用'Gon'gem將數據從Rails傳遞給Javascript一段時間,然後我切換到可以正常工作的狀態。我現在將把我的整個Rails轉換成Javascript通信給Gon寶石。