【发布时间】:2013-08-04 13:20:22
【问题描述】:
我是 ruby 和 rails 的新手。我已经完成了僵尸教程和其他一些教程。
我使用我的虚拟主机上的工具生成了一个默认的 Rails 应用程序。
我将 rails 连接到数据库,并能够显示包含其中值的页面。
从我的所有搜索中我相信,只需将我的视图文件命名为 *.html.erb 就足以使它们以 html 的 mime 类型呈现。
问题是页面显示为 Content-Type: text/plain。
这就是我所拥有的
config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :enrollapplications
end
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
end
app/controllers/enrollapplications_controller.rb
class EnrollapplicationsController < ApplicationController
def show
@enrollapp = Enrollapplication.find(params[:id])
end
end
app/views/layouts/application.html.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Enrollment Application</title>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
app/views/enrollapplications/show.html.erb
<h3>show stuff</h3>
<h1><%= @enrollapp.firstName %></h1>
curl -I example.com/Application/enrollapplications/1
HTTP/1.1 200 OK
Date: Sun, 28 Jul 2013 17:37:36 GMT
Content-Type: text/plain
请随意指出并嘲笑我的错误。
【问题讨论】:
-
我使用虚拟主机上的工具生成了一个默认的 Rails 应用程序。这就是问题所在,您需要详细说明。
-
您通过
curl -l拨打的网址是什么? Ruby 不像 PHP(例如)——如果你请求一个.erb文件并且它可以通过网络访问,它不会导致 Ruby 应用程序执行。 -
我的主机有一个 Rails 管理工具,可以生成一个已存根的 Rails 应用程序并部署它。它所要求的只是一个名字。
-
另外,看起来版本(我无法控制)是 Rails 2.3.18。
-
@Diver 您可以尝试在本地运行 Rails 进行修补,以消除可能导致此类问题的潜在变量。这绝对不是预期或常见的行为。你看到卷曲响应中的
<%标签了吗?
标签: ruby-on-rails ruby