Ruby on Rails map.root似乎不起作用

时间:2021-02-08 00:06:06

I am trying to get the root of my application to route to a default controller. From what I read, this should be possible with something like this at the bottom of my routes.rb file:

我试图让我的应用程序的根路由到路由到默认控制器。从我读到的内容来看,应该可以在routes.rb文件的底部使用类似的东西:

map.root :controller => 'albums'

or perhaps even:

或者甚至是:

map.home  '', :controller => 'albums'

However, when I try navigating to http://myhost:8000/, I just see the rails welcome page. I am restarting the application with the following command after making the change to routes.rb and before testing it:

但是,当我尝试导航到http:// myhost:8000 /时,我只看到rails欢迎页面。在对routes.rb进行更改并在测试之前,我使用以下命令重新启动应用程序:

sudo mongrel_cluster_ctl restart

Here is some more possibly pertinent environment information:

以下是一些可能相关的环境信息:

% rails -v
Rails 2.3.3

% ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

I am sure I'm missing something simple, but I can't see what it is. Any ideas?

我确信我错过了一些简单的东西,但我看不出它是什么。有任何想法吗?

6 个解决方案

#1


16  

Have you deleted the static public/index.html page that Rails creates? If this is still in your app it will be shown instead of the root page you defined in the routes.

您是否删除了Rails创建的静态public / index.html页面?如果这仍然在您的应用程序中,它将显示而不是您在路线中定义的根页面。

#2


13  

Delete the public/index.html file.

删除public / index.html文件。

#3


3  

map.root :controller => 'albums'

Is the correct syntax.

是正确的语法。

A few things to try:

一些事情要尝试:

  • delete index.html from public.
  • 从公共中删除index.html。
  • Look at the output of "rake routes", do you see something along the lines of:
  • 看看“rake routes”的输出,你看到的内容如下:
root   /  {:controller=>"albums", :action=>"index"}
  • Are you 100% sure the right cluster is being restarted: try running script/server and navigating to root on port 3000
  • 您是否100%确定正在重新启动正确的群集:尝试运行脚本/服务器并在端口3000上导航到root

#4


1  

Routes at the end of routes.rb are the last to get used, therefore you may want to try with 'map.root...' at the top of your routes.rb

routes.rb末尾的路由是最后使用的路由,因此您可能想尝试使用您路由顶部的'map.root ...'.rb

#5


0  

I was scratching my head for a while now. Deleting public/index.html file did the glitch for me. Thanks!

我现在挠了一会儿。删除public / index.html文件对我来说是个小问题。谢谢!

#6


0  

I have a slightly different problem. I've set up a map.root entry and it works with mongrel. However when I use apache2 as the web server with Passenger module I get a '500' error. If I re-instate my /public/index.html then it works under apache2.

我有一个稍微不同的问题。我已经设置了map.root条目,它可以与mongrel一起使用。但是,当我使用apache2作为带有Passenger模块的Web服务器时,我收到“500”错误。如果我重新启动我的/public/index.html,那么它可以在apache2下运行。

I have tried to go directly as:

我试图直接去:

http:///home/index

HTTP:///家/索引

This also gives me the same '500' error.

这也给了我相同的'500'错误。

Please can somebody tell me what I'm doing wrong?

请有人能告诉我我做错了什么吗?

Hi

你好

I found someone else who had had the same problem. Turns out that Passenger is running in production mode whilst my app was in development mode.

我找到了其他有同样问题的人。事实证明,当我的应用程序处于开发模式时,Passenger正在生产模式下运行。

I put Passenger into development mode by adding the following line to my Virtual Hosts file

我通过将以下行添加到我的虚拟主机文件中将Passenger置于开发模式

RailsEnv = development

RailsEnv =开发

Restarted Apache and it all works!!

重启Apache,一切正常!

Phew!

唷!

Purvez

Purvez

#1


16  

Have you deleted the static public/index.html page that Rails creates? If this is still in your app it will be shown instead of the root page you defined in the routes.

您是否删除了Rails创建的静态public / index.html页面?如果这仍然在您的应用程序中,它将显示而不是您在路线中定义的根页面。

#2


13  

Delete the public/index.html file.

删除public / index.html文件。

#3


3  

map.root :controller => 'albums'

Is the correct syntax.

是正确的语法。

A few things to try:

一些事情要尝试:

  • delete index.html from public.
  • 从公共中删除index.html。
  • Look at the output of "rake routes", do you see something along the lines of:
  • 看看“rake routes”的输出,你看到的内容如下:
root   /  {:controller=>"albums", :action=>"index"}
  • Are you 100% sure the right cluster is being restarted: try running script/server and navigating to root on port 3000
  • 您是否100%确定正在重新启动正确的群集:尝试运行脚本/服务器并在端口3000上导航到root

#4


1  

Routes at the end of routes.rb are the last to get used, therefore you may want to try with 'map.root...' at the top of your routes.rb

routes.rb末尾的路由是最后使用的路由,因此您可能想尝试使用您路由顶部的'map.root ...'.rb

#5


0  

I was scratching my head for a while now. Deleting public/index.html file did the glitch for me. Thanks!

我现在挠了一会儿。删除public / index.html文件对我来说是个小问题。谢谢!

#6


0  

I have a slightly different problem. I've set up a map.root entry and it works with mongrel. However when I use apache2 as the web server with Passenger module I get a '500' error. If I re-instate my /public/index.html then it works under apache2.

我有一个稍微不同的问题。我已经设置了map.root条目,它可以与mongrel一起使用。但是,当我使用apache2作为带有Passenger模块的Web服务器时,我收到“500”错误。如果我重新启动我的/public/index.html,那么它可以在apache2下运行。

I have tried to go directly as:

我试图直接去:

http:///home/index

HTTP:///家/索引

This also gives me the same '500' error.

这也给了我相同的'500'错误。

Please can somebody tell me what I'm doing wrong?

请有人能告诉我我做错了什么吗?

Hi

你好

I found someone else who had had the same problem. Turns out that Passenger is running in production mode whilst my app was in development mode.

我找到了其他有同样问题的人。事实证明,当我的应用程序处于开发模式时,Passenger正在生产模式下运行。

I put Passenger into development mode by adding the following line to my Virtual Hosts file

我通过将以下行添加到我的虚拟主机文件中将Passenger置于开发模式

RailsEnv = development

RailsEnv =开发

Restarted Apache and it all works!!

重启Apache,一切正常!

Phew!

唷!

Purvez

Purvez