English 中文(简体)
找到解决方案:cPanel创建的Ruby On Rails设置为任何视图返回空白页
原标题:Solution found: cPanel-created Ruby On Rails setup returns blank pages for any views

Solution found!

这似乎是Rails+cPanel使用的Web服务器Mongrel+Rails 2.3.8特有的错误。这就是为什么它只在您从cPanel运行应用程序时显示,而在通过脚本/服务器本地提供应用程序时不显示。

For more details, see: https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238

最终找到的解决方法是将以下文件放在每个新Rails 2.3.8应用程序的/config/initializers目录中:

https://gist.github.com/471663

一旦我添加了这个初始值设定项,我的Rails应用程序就会按预期运行。

Original question:

我已经在railsforzombies.org上完成了非常有用的教程,现在准备进行RoR安装测试。我的网站位于共享主机上,使用cPanel。我使用cPanel创建了测试应用程序,并在~/rails_apps/blog上进行了设置。我创建了一个重写,将mydomain.com/testblog/重定向到mydomain.com:12002,这是cPanel运行RoR应用程序的端口。我还通过cPanel以开发模式启动了该应用程序。

如果我访问mydomain.com/testblog/,我会看到一个有用的页面,让我知道我的RoR应用程序已经创建并正在运行。很棒,对吧?嗯,没那么快。

我遵循指南.rubyonrails.org/v2.3.8/Getting_Started.html上的《入门》指南,然后进入第4步。我运行了script/generate controller home index,并在app/views/home/index.html.erb上编辑了生成的视图

<h1>Hello rails!</h1>

然而,当我访问mydomain.com/testblog/home/index(带或不带尾部/)时,我的浏览器中会出现一个空白页面,什么都没有(View Source什么都没有显示)。

为了确保我不会发疯,我在rails应用程序的/public目录中放了一个文本文件,当我转到mydomain.com/testblog/test.txt时,它会得到正确的服务。所以我知道cPanel中的Apache重写工作正常。

有什么想法吗?我想我忽略了一些显而易见的事情,但我现在还一片空白。

作为参考,我在cPanel 11、Ruby 1.8.7和Rails 2.3.8上运行。我很想运行Rails3.0,但共享主机说目前还不能。

编辑后添加:

生成上面的主控制器和索引操作将以下行添加到我的routes.rb文件中(我已经检查过了,它们就在那里):

map.connect  :controller/:action/:id 
map.connect  :controller/:action/:id.:format 

因此mydomain.com/testblog/home/index应该映射到app/views/home/index.html.erb。

再次编辑,包含更多调查详细信息:

我发现了一些可能会对这件事有所启发的东西。如果我在cPanel中停止rails应用程序,然后通过PuTTY登录并使用script/server启动开发服务器并执行

curl http://0.0.0.0:3000/home/index

dev服务器的响应为

<h1>Hello Rails!</h1>

来自app/views/home/index.html.erb。所以它在那里工作。当我在cPanel中启动Rails应用程序时(它告诉我它在端口12002上运行),我从mydomain.com/testblog/home/index收到一个空响应

curl http://0.0.0.0:12002

如果我在服务器上通过SSH运行它。所以它看起来像是cPanel的怪异之处,而不是Rails。

问题回答

你是否确定并删除了应用程序的app/public目录中的index.html文件?

此外,在生成家庭控制器后,您是否设置了routes.rb来识别新的控制器和操作?





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签