【发布时间】:2011-08-10 11:37:27
【问题描述】:
我正在使用 Rails 3,感觉更改索引 (http://localhost:3000) 路由的语法与以前的版本不同。
我想打开员工控制器的动态索引页面 (index.html.erb)(现在可以使用 localhost:3000/employees 打开)作为默认页面 (localhost:3000)。我认为这很容易,因为在路线中它是这样写的:
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
这就是我实际所做的:我删除了public/index.html 并设置了root :to => "employees#index"。
但是当我打开服务器并打开localhost:3000时,它仍然在打开“欢迎国外!”-页面。很奇怪!
所以我用谷歌搜索了这个问题并找到了答案,我应该把它写到我的路由文件中:
map.root :controller => 'employees', :action => 'index'
这里也一样——我仍然得到“欢迎出国!”页面,rails-shell 显示“未定义的局部变量或方法'map'”。 (我认为这是 Rails 2 的旧语法...?)
match "/" => "employees#index" 说routing error: No route matches "/"
那么我做错了什么?我怎么解决这个问题?
【问题讨论】:
-
看起来你 DIDN'T 删除
public/index.html:) -
删除public/index.html后确定重启服务器吗?
-
嘿???我不明白,但现在它工作了。我肯定(100%)删除了 public/index.html。我也再次重新启动了服务器。我什至清理了我的回收站......毕竟这没有帮助。唯一有帮助的是从文件夹中删除图片 (public/images/rails.png)。在那之后,我得到了我的索引页。真的很奇怪...谢谢!
标签: ruby-on-rails ruby-on-rails-3 routes