2017-05-06 83 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