【发布时间】:2015-03-18 10:35:35
【问题描述】:
我正在尝试显示日志文件的内容,即 html 中的 txt 文件。 我收到“模板丢失错误”。
Missing template application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/home/Documents/workspace/demo2/app/views"
在我的控制器中我有
class ApplicationController < ActionController::Base
def index
end
def displaycontents
send_file "/home/Documents/workspace/demo.txt",
:type => "text/html",
:disposition => 'inline'
end
end
在我的 routes.rb 我有
root 'application#index'
在我的 index.html.erb 我有
<!DOCTYPE html>
<html>
<head>
<title>new view</title>
</head>
<body>
<%= link_to "Log File", :controller=> :application,
:action=>:displaycontents %>
</body>
</html>
我已将控制器文件中的 index 操作保留为空,因此 index.html.erb 会默认呈现。
我已经按照另一个解决方案的建议重新启动了 rails 服务器。 并且 index.html.erb 文件存在于 demo2/app/views 中。
我使用的不同版本是 - 红宝石版本:1.8.23 - 红宝石版本:1.9.3 -导轨:4.0.2
【问题讨论】:
-
demo2/app/views?模板应放在 demo2/app/views/application 下。可以试试吗?
-
什么时候出现这个错误?当您转到
localhost:3000或单击链接时?
标签: ruby-on-rails ruby ruby-on-rails-4