Ruby-on-rails Rails 消息:ActionView::MissingTemplate
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3019369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails message: ActionView::MissingTemplate
提问by rtfminc
I am getting an error that I cannot figure out:
我收到一个我无法弄清楚的错误:
ActionView::MissingTemplate (Missing template cluster/delete_stuff.erb in view path app/views)
<...snip trace...>
Rendering rescues/layout (internal_server_error)
I am "enhancing" others code and am following the convention they set up, where they have have code like:
我正在“增强”其他代码并遵循他们设置的约定,他们的代码如下:
<%= render :partial => "other_stuff" %>
And a file named _other_stuff.html.erband it all works, but when I copy these little snippets, I get the above error. Any ideas? Something is going on here that I need to figure out.
还有一个名为_other_stuff.html.erb的文件,一切正常,但是当我复制这些小片段时,出现上述错误。有任何想法吗?这里发生了一些事情,我需要弄清楚。
回答by rtfminc
Turns out that I did not have a
原来我没有
render :something
render :something
in my controller method, so I guess Rails figured that there must be a "delete_stuff.erb" somewhere to know what to do. Added a render and the error message goes away.
在我的控制器方法中,所以我猜 Rails 认为某个地方必须有一个“delete_stuff.erb”才能知道该怎么做。添加了渲染,错误消息消失了。
回答by theIV
ActionViewwill look for templates/partials in the current controllers view folder, unless its view path has been changed in the controller—you can prepend and appenddifferent view paths for it to try and match first. Since you mention partials specifically, have a look at the documentation on partials.
ActionView将在当前控制器视图文件夹中查找模板/部分,除非它的视图路径已在控制器中更改 - 您可以预先添加和附加不同的视图路径以使其首先尝试匹配。由于您特别提到了 partials,请查看有关partials的文档。
Do you have a _delete_stuff.html.erbfile in your views/cluster directory? If not, where is the _delete_stuff.html.erbpartial? If it's not in the same directory, you will have to call render :partial => 'other_directory/delete_stuff'for your partial to appear.
_delete_stuff.html.erb您的 views/cluster 目录中有文件吗?如果不是,_delete_stuff.html.erb部分在哪里?如果它不在同一目录中,您将不得不要求render :partial => 'other_directory/delete_stuff'您的部分出现。

