模板缺少错误

时间:2013-06-06 06:52:05

标签: ruby-on-rails ruby templates

我正在尝试在localhost:3000/posts上发布简单的博文。

当我尝试访问该页面时,收到此错误。

Template is missing

Missing template posts/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "c:/Sites/myrubyblog/app/views" 

以下是我posts_controller.rb中的代码副本:

class PostsController < ApplicationController
    def index

    end
end

我的index.html.erb目录中有c:/Sites/myrubyblog/app/views文件,所以我不确定为什么会这样。

有谁能告诉我应该怎么做才能解决这个问题?

3 个答案:

答案 0 :(得分:0)

index.html.erb移至posts文件夹内的rubyblog/app/views/posts

答案 1 :(得分:0)

您的index.html.erb文件应位于c:/Sites/myrubyblog/app/views/posts

答案 2 :(得分:0)

您应该将视图代码放在相应的文件夹中。

在您的情况下,您应将index.html.erb放入c:/Sites/myrubyblog/app/views/posts/文件夹

模板丢失当它无法找到视图文件时出现错误。