在我的Rails 4.2应用程序中,它包含一些Rails引擎,需要引擎itemlized_spendingx
使用ajax调用在引擎biz_workflowx
中呈现文件。引擎biz_workflowx
包含在itemlized_spendingx
的应用程序控制器中,如下所示:
module ItemlizedSpendingx
class ApplicationController < ::ApplicationController
include BizWorkflowx::WfHelper
end
end
在BizWorkflowx::WfHelper
中,有一个动作event_action
定义,它在引擎link_to
的索引视图中被称为ajax与itemlized_spendingx
。这是响应ajax调用的event_action.js.erb
$("#newworkflow .modal-content").html('<%= j render(:file => "biz_workflowx/application/event_action.html.erb") %>');
$("#newworkflow").modal();
上面的evant_action.js.erb
的目的是使用Bootstrap模式弹出event_action.html.erb
(event_action.js.erb和event_action.html.erb驻留在biz_workflowx / app / views / application /下的同一子目录中)的视图。我遇到的问题是render(:file => ..)
引发template missing
的错误,即使File.file?('biz_workflows/app/views/application/event_action.html.erb
)在true
返回ActionView resolver
。
似乎render
真的很难找到event_action.html.erb
,即使File.file?
看到它。如何让渲染器看到它?
这是有效的event_action.js.erb
:
$("#newworkflow .modal-content").html('<%= j render(:file => "/application/event_action.html.erb") %>');
$("#newworkflow").modal();
删除biz_workflowx
后,找到视图模板。似乎Rails视图在相对路径中解析视图模板,并在event_action.html.erb
的范围内处理itemlized_spendingx
。