2017-05-06 84 views
0

在由幾個Rails引擎組成的Rails 4.2應用程序中,需要引擎itemlized_spendingx通過ajax調用來渲染引擎biz_workflowx中的文件。發動機biz_workflowx被包括在這樣itemlized_spendingx的應用控制器:Rails 4.2:如何渲染包含引擎中的文件?

module ItemlizedSpendingx 

    class ApplicationController < ::ApplicationController 

     include BizWorkflowx::WfHelper 

    end 
    end 

BizWorkflowx::WfHelper,存在定義的動作event_action它被稱爲AJAX與link_to從索引視圖中發動機itemlized_spendingx。這裏是event_action.js.erb響應AJAX調用

$("#newworkflow .modal-content").html('<%= j render(:file => "biz_workflowx/application/event_action.html.erb") %>'); 
$("#newworkflow").modal(); 

上述evant_action.js.erb的目的是彈出的event_action.html.erb(一個視圖都event_action.js.erb和event_action.html.erb駐留在相同的子目錄下biz_workflowx /應用/ views/application /)與Bootstrap模態。我遇到的問題是即使File.file?('biz_workflows/app/views/application/event_action.html.erb)在ActionView resolver中返回truerender(:file => ..)也會產生template missing的錯誤。

看起來render真的很難找到event_action.html.erb,即使File.file?看到它。如何讓渲染器看到它?謝謝。

回答

1

這裏是工作的event_action.js.erb

$("#newworkflow .modal-content").html('<%= j render(:file => "/application/event_action.html.erb") %>'); 
$("#newworkflow").modal(); 

取出biz_workflowx後,再視圖模板中找到。看來,Rails視圖在相對路徑中解析了視圖模板,並在itemlized_spendingx的範圍內對待event_action.html.erb