Ruby On Rails:显示 html 源代码而不是渲染它

发布于 2024-09-09 01:54:51 字数 2000 浏览 6 评论 0原文

我有一个大问题(甚至我的服务器管理员似乎也很难解决它)。

我使用我的 cpanel (11.25.0-STABLE) 创建了一个新的 ruby​​ on Rails 应用程序,该应用程序在访问其原始 uri(带有端口号)时工作正常。

为了使该 uri 更加“用户友好”,我创建了一个重写来访问我的 RoR 应用程序,而不显示端口号。

的 .htaccess 内容

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^greendeers.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.greendeers.com$
RewriteRule ^.*$ "http\:\/\/127\.0\.0\.1\:12001%{REQUEST_URI}" [P,QSA,L]

我重写的 uri app/controllers/helloworld_controller.rb

class HelloworldController < ApplicationController
  def index
  end
end

app/views/layouts/helloworld.html.erb

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title><%= controller.controller_name %>: <%= controller.action_name %></title>
  <%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

  <p style="color: green"><%= notice %></p>

  <%= yield %>

</body>
</html>

app/views/helloworld/index.html.erb

<h1>HELLO WORLD</h1>

第一页(由 RoR 创建的原始页面)工作正常与两个 uri,但是当访问我的控制器之一时,不会呈现 html,而是显示 html 代码。

http://www.greendeers.com/helloworld

此页面使用原始 uri 按预期呈现(相同如上所述,端口号:12001)

访问两个 uri 时,我的日志显示相同的内容:

处理 HelloworldController#index(针对 2010-07-10 02:53:20 的 [我的 IP 地址])[GET]

layout/helloworld 中的渲染模板

渲染 helloworld/index

在 1 毫秒内完成(视图:1,数据库:0)| 200 好的 [http://greendeers.com/helloworld]

您知道如何修复它吗?

抱歉,我目前每个帖子只能发布一个链接:/

I have a big problem (even my server's admin seems to have some difficulties to solve it).

I used my cpanel (11.25.0-STABLE) to create a new ruby on rails application, which work fine when accessed to its original uri (with port number).

To make that uri more "user friendly", I have created a rewrite to access my RoR application without showing the port number.

Content of my .htaccess for my rewritten uri

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^greendeers.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.greendeers.com$
RewriteRule ^.*$ "http\:\/\/127\.0\.0\.1\:12001%{REQUEST_URI}" [P,QSA,L]

app/controllers/helloworld_controller.rb

class HelloworldController < ApplicationController
  def index
  end
end

app/views/layouts/helloworld.html.erb

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title><%= controller.controller_name %>: <%= controller.action_name %></title>
  <%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

  <p style="color: green"><%= notice %></p>

  <%= yield %>

</body>
</html>

app/views/helloworld/index.html.erb

<h1>HELLO WORLD</h1>

The first page (original one created by RoR) works fine with both uri, but when accessing one of my controller, the html is not rendered, instead, the html code is displayed.

http://www.greendeers.com/helloworld

This page renders as expected using the original uri (same as above, with port number :12001)

My log display the same thing when accessing both uri:

Processing HelloworldController#index (for [My ip address] at 2010-07-10 02:53:20) [GET]

Rendering template within layouts/helloworld

Rendering helloworld/index

Completed in 1ms (View: 1, DB: 0) | 200 OK [http://greendeers.com/helloworld]

Do you have a clue on how to fix it?

Sorry, I can only post one link per post at the moment :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潦草背影 2024-09-16 01:54:51

这是因为你的 .htaccess 使用不当。

请改用代理系统或乘客。不是你的重写规则

It's because you use badly your .htaccess.

Use a proxy system or passenger instead . Not your rewrite rules

霓裳挽歌倾城醉 2024-09-16 01:54:51

我修好了。这与杂种有关。我在这里找到了解决方案:

https://rails.lighthouseapp.com/projects/8994/门票/4690

:)

I fixed it. It was something to do with mongrel. I found the solution here:

https://rails.lighthouseapp.com/projects/8994/tickets/4690

:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文