0

St. Laurent & Edd Dumbill の Learning Rails book を使用しています。上記の chp3 のレイアウト演習からビューを分割すると、テンプレートが見つからないというエラーが発生します。

以下のエラーが発生する理由を理解してください。

テンプレートがありません ビュー パス C:/Instantrails/rails_apps/hello/app/views にレイアウト layouts/hello.html.erb がありません

コントローラー情報: 名前: hello_controller

パス: C:\INSTAN~1\rails_apps\hello\app\controllers

コード:

class HelloController <ApplicationController

def index
@message="Hello!"

@count=3

@bonus="This message came from the controller."
end

終わり

情報を見る:

名前: index.html

パス: C:\INSTAN~1\rails_apps\hello\app\views\hello

コード:

<h1><%=h @message %></h1>
<p>This is a greeting from app/views/hello/index.html.erb</p>
<% for i in 1..@count %>
<p><%= @bonus %></p>
<% end %>

名前: hello.html.erb

パス: C:\INSTAN~1\rails_apps\hello\app\views\layouts

コード:

<html>
<head><title><%=h @message %> </title>
<% stylesheet_link_tag 'hello' %>

</head>
<body>
(using layout)
<!--layout will incorporate view-->
<%= yield :layout %>

</body>
</html>
4

2 に答える 2

0

おそらく、コントローラーファイルにレイアウト名を含めるのを忘れているでしょう:

class HelloController  < ApplicationController

 layout "Hello" 

 def index
  #your code goes here.
 end

そのレイアウト セクションは app/views/Layouts/hello.html.erb を探します。

于 2013-10-20T20:19:17.757 に答える