-2

如何在我的控制器上的 ruby​​ 中解决此错误“模板丢失”

class SayController < ApplicationController
  def hello
    @title = "Ruby on Rails"
    @website = "www.9lessons.info"
  end
end

我的html页面是

<html>
  <head>
   <title><%= @title %></title>
  </head>
  <body>
    <h1>Welcome to <%= @website %></h1>
    Addition : <%= 100 + 300 %>
  </body>
</html>
4

1 回答 1

-1

您的 def 方法名称需要与您的视图名称匹配。

IE

def index
end

必须是 index.html.erb

def hello
end 

将是 hello.html.erb

def world 
end 

将是 world.html.erb

如果不是,您将得到一个缺少的模板,因为它正在寻找该特定名称。

于 2013-03-08T14:22:31.540 回答