【问题标题】:Ruby On Rails: Display html source code instead of rendering itRuby On Rails:显示 html 源代码而不是渲染它
【发布时间】:2011-06-07 00:51:32
【问题描述】:

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

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

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

我重写的 uri 的 .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]

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 (for [My ip address] at 2010-07-10 02:53:20) [GET]

在 layouts/helloworld 中渲染模板

渲染 helloworld/index

在 1 毫秒内完成(查看:1,DB:0)| 200 好 [http://greendeers.com/helloworld]

你知道如何解决它吗?

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

【问题讨论】:

    标签: html ruby-on-rails url-rewriting rendering cpanel


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复。你能告诉我更多关于乘客的信息吗?我刚开始用RoR,不太了解。
    • 除了这两个之外还有其他解决方案吗?我的网络托管服务提供商不允许我安装Passenger……我开始怀疑与他们合作是否是正确的决定。否则我将不得不将我的网站移动到其他地方。
    【解决方案2】:

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

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

    :)

    【讨论】:

    • 此 URL 无法再访问。你能解释一下解决方案吗?
    • @etienne - 似乎 Rails 问题已从 Lighthouse 迁移到 GitHub:github.com/rails/rails/issues/404 您也许可以在 here 的某个地方找到该问题。可悲的是,看起来他们并没有继承旧的问题 ID。 This might 帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-01
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    相关资源
    最近更新 更多