index.html.erb在Rails

时间:2017-11-23 14:08:59

标签: ruby-on-rails ruby render

我创建了一个项目,其中index.html.erb无法正确呈现,当我使用application.html.erb时,当我删除该文件时一切正常

   Home Controller
   class HomeController < ApplicationController
   end

   Routes file
   Rails.application.routes.draw do
   # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
   root "home#index"
   resources :posts
   end

   application.html.erb
   <!DOCTYPE html>
   <html>
   <head>
   <title>Project</title>
  <%= stylesheet_link_tag    "application" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
 </head>

 <body>
 <%= yield%>
 </body>
</html>

1 个答案:

答案 0 :(得分:0)

您需要在index的{​​{1}}中定义您引用的routes.rb操作。为此,您必须在HomeController中定义index方法,因此:

HomeController
相关问题