如何在Rails 4.2中呈现包含引擎的文件?

问题描述 投票:0回答:1

在我的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?看到它。如何让渲染器看到它?

ruby-on-rails ruby-on-rails-4 rails-engines
1个回答
1
投票

这是有效的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

© www.soinside.com 2019 - 2024. All rights reserved.