渲染中缺少模板:当Rails 4.2中存在该文件时,ajax调用中的文件

时间:2017-05-04 05:13:57

标签: ruby-on-rails ruby-on-rails-4

Ajax用于Bootstrap模式调用。成功调用js.erb文件,然后此js.erb文件应加载html.erb驻留在与js.erb位于biz_workflowz/app/views/application/下的同一子目录中。这是js.erb文件:

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

但是找不到event_action.html.erbaction_view/path_sets.rb中出现错误:

def find(*args)
  find_all(*args).first || raise(MissingTemplate.new(self, *args)) #find_all(*args).first returns NIL
end

错误是:

    ActionView::Template::Error (Missing template c:/d/code/rails_proj/engines/biz_workflowx/app/views/application/event_action.html.erb with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}. Searched in:
   .......
      * "C:/D/code/rails_proj/engines/biz_workflowx/app/views" #<<== did search the subdir but did not find anything
      * "C:/D/code/rails_proj/engines/searchx/app/views"
      * "C:/D/code/rails_proj/engines/commonx/app/views"
      * "C:/D/code/rails_proj/engines/authentify/app/views"
      * "C:/D/code/rails_proj/webportal"
      * "C:/"
    ):
        1: $("#newworkflow .modal-content").html('<%= j render(:file => "biz_workflowx/application/event_action.html.erb") %>');
        2: $("#newworkflow").modal();
      actionview (4.2.0) lib/action_view/path_set.rb:46:in `find'

即使使用文件event_action.html.erb的硬编码路径,它仍会返回template missing。类似的js.erb代码已经在一些地方用于ajax调用,我不明白为什么它在这里不起作用。什么可能导致此错误?

更新

以下是调试窗口,显示biz_workflowz/app/views已搜索resolver,但/application/下未看到该文件。奇怪!

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

event_action.html.erb

下添加c:/d/code/rails_proj/engines/biz_workflowx/app/views/application个文件