没有路线匹配“/”?

时间:2011-08-18 17:05:34

标签: ruby-on-rails ruby-on-rails-3

我知道这似乎是一个非常简单的错误,但它来自一个复杂的过程。

我正在尝试将旧的rails 2应用程序升级到rails 3.在我的routes.rb文件中,我有

root :to => "home#index"

我还有一个文件'app / controllers / home_controller.rb'和'app / views / home / index.html.erb'所以我根本得不到可能导致此错误的原因。升级到rails 3并不容易。

(在home_controller.rb中,我有def index end

有什么建议吗?

** 更新 - 完整的路径文件 * *

 SpecimenTracker::Application.routes do
  map.resources :users

  map.resource :session

  # The priority is based upon order of creation: first created -> highest priority.

  # Sample of regular route:
  #   map.connect 'products/:id', :controller => 'catalog', :action => 'view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   map.resources :products

  # Sample resource route with options:
  #   map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }

  # Sample resource route with sub-resources:
  #   map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller

  # Sample resource route with more complex sub-resources
  #   map.resources :products do |products|
  #     products.resources :comments
  #     products.resources :sales, :collection => { :recent => :get }
  #   end

  # Sample resource route within a namespace:
  #   map.namespace :admin do |admin|
  #     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
  #     admin.resources :products
  #   end

  # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
get "home/index"
root :to => "home#index"
  # See how all your routes lay out with "rake routes"

  # Install the default routes as the lowest priority.
  # Note: These default routes make all actions in every controller accessible via GET requests. You should
  # consider removing the them or commenting them out if you're using named routes and resources.
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

4 个答案:

答案 0 :(得分:5)

“map.connect”,“map.resources”是旧语法

My Rails 3 routes.rb以

开头
ApplicationName::Application.routes.draw do

Rails从外部路由:http://guides.rubyonrails.org/routing.html

答案 1 :(得分:0)

为了确保,您是否尝试重新启动Webrick(或您正在使用的任何其他服务器)。虽然这很简单,但总会让你绊倒:)

如果这不是问题,请发布您的日志文件(log / development.log)。

编辑:刚看到您帖子的更新。尝试逐行删除路径文件中的其他(未注释)行,直到问题得到解决。

答案 2 :(得分:0)

删除两个map.connect语句。你在铁轨3中不需要它们。

并且顶部的资源应该只是:

  resources :users
  resources :sessions

答案 3 :(得分:0)

尝试:

root :to => 'home#index'

注意单引号。 #在Ruby中的双引号字符串中具有特殊含义。