0

Note: App is using Rails 3.2.1 and Ruby 1.9.3.

I'm attempting to set up a rails app using Passenger and Apache 2. When the applications is initially created it loads the default rails page fine using the default index.html file in /public.

The problem arises when I run rails generate controller home index and delete the index.html file. Then, in my routes.rb file I added root :to => "home#index". I then get an error saying 'We're sorry, but something went wrong.'

My error log says File does not exist and when I add back in the index.html it loads fine again.

So, it seems it is still looking for the index.html file even after I delete it.

I'm probably missing something very obvious, so any help is greatly appreciated

4

1 回答 1

1

由于您已将根定义为"home#index",因此您必须有一个 HomeController 具有索引方法和位于app/views/home/index.html.erb

通常,控制器方法为视图“准备”数据,这意味着大多数控制器方法都以调用结束,render为视图提供选项。

这种模式非常常见,如果您只想显示标准视图,则无需调用 render。标准视图位于app/views/[controller_name]/[action_ame](.[request_format])(.[precompilation_format)

如果您在公共文件夹中有旧的 index.html 文件,则会提供静态文件并且不会触发您的控制器。如果您没有该文件,则会触发您的控制器,并且您的索引方法现在正在尝试查找“索引”文件,但在app/views/home/index.

是可选的request_format,如果您的站点仅为 html,通常会被省略。当您的操作可以使用 html、json、xml 进行响应时,它会变得很有用...

html request_format 通常是 erb ,precompilation_format但还有更多(haml、rabl、builder、...)

于 2012-02-19T21:00:36.887 回答