简体   繁体   English

Rails 2.2.2-尝试在子目录中呈现部分时丢失模板错误

[英]Rails 2.2.2 - Missing template error when trying to render a partial in a subdirectory

I'm getting the following error when Rails tries to render my layout located in app/views/layouts/application.html.erb : 当Rails尝试渲染位于app / views / layouts / application.html.erb中的布局时,出现以下错误:

Missing template shared/_header.erb in view path /home/me/checkout/site/app/views: Extracted source (around line #11): 视图路径/ home / me / checkout / site / app / views中缺少模板shared / _header.erb:提取的源(第11行附近):
8: <body>
9: <div id="wrap">
10: <div class="clear">...</div>
11: <%= render :partial => 'shared/header' %>

What's weird about all of this is that I have a directory named shared inside of app/views . 所有这些奇怪的是我在app / views内部有一个名为shared的目录。 Inside there I have a file named _header.html.erb . 在其中,我有一个名为_header.html.erb的文件。 I'm using Ruby 1.8.7, Rails 我正在使用Ruby 1.8.7,Rails
2.2.2, and following the documentation found here . 2.2.2,并遵循此处找到的文档。

Update: Even more weirdness. 更新:更奇怪。 This code works under Windows using InstantRails (Ruby 1.8.6, Rails 2.2.2). 此代码在Windows下使用InstantRails(Ruby 1.8.6,Rails 2.2.2)运行。 However, render :template doesn't seem to work. 但是,render:template似乎不起作用。 I'll keep on investigating. 我会继续调查。

If what you typed is correct, your partial is misnamed. 如果您输入的内容正确,则您的部分名称被错误命名。 It should be "_header.html.erb" and not "_header.erb.html". 它应该是“ _header.html.erb”,而不是“ _header.erb.html”。 This is probably why Rails is not finding it. 这可能是Rails找不到它的原因。

It has been quite a while since I have touched Rails 2.2, but I believe that you are looking for the following: 自从接触Rails 2.2以来已经有一段时间了,但是我相信您正在寻找以下内容:

<%= render :template => 'shared/header' %>

Edit: To whoever else is down down voting this, try reading the 2.2.2 docs and actually trying it first. 编辑:如果其他人对此不赞成,请尝试阅读2.2.2文档,然后首先尝试。 This was a big gotcha back then. 那时真是个大难题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM