早上好!
我在routes.rb
创建 的路线时,找不到我的路线。当我加载localhost:3000/Manage/Delete/1
时,我抛出了No route matches [GET] "/Manage/Delete/1"
条消息。这没有意义,因为我已经在routes.rb
中明确定义了它:
# You can have the root of your site routed with "root"
root 'welcome#index'
# Example of regular route:
get 'Portfolio' => 'my_work#index'
get 'Posts/:id' => 'posts#with_id'
get 'Contact' => 'contact#index'
get 'Contacted' => 'contact#contacted'
get 'Manage' => 'manage#index'
get 'Manage/Create' => 'manage#create'
get 'Manage/Delete/:id' => 'manage#delete'
get '404' => 'problems#_404'
get '422' => 'problems#_422'
get '500' => 'problems#_500'
post 'Contact' => 'contact#send_message'
# Problem pages
match '/404', to: 'problems#_404', via: :all
match '/422', to: 'problems#_422', via: :all
match '/500', to: 'problems#_500', via: :all
我已经做了一切,从重新启动我的服务器到确保我在开发环境中,我仍然遇到了这个问题。我做有一个视图,我做在我的控制器中有一个方法(它只是一个空方法),我做有路线。以下是我加载页面时日志中发生的情况:
Started GET "/Manage/Delete/1" for ::1 at 2015-07-25 08:54:34 -0400
ActionController::RoutingError (No route matches [GET] "/Manage/Delete/1"):
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.1) lib/rack/content_length.rb:15:in `call'
puma (2.9.1) lib/puma/server.rb:490:in `handle_request'
puma (2.9.1) lib/puma/server.rb:361:in `process_client'
puma (2.9.1) lib/puma/server.rb:254:in `block in run'
puma (2.9.1) lib/puma/thread_pool.rb:92:in `call'
puma (2.9.1) lib/puma/thread_pool.rb:92:in `block in spawn_thread'
Rendered /Users/alexander/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
Rendered /Users/alexander/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/routes/_route.html.erb (1.5ms)
Rendered /Users/alexander/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/routes/_table.html.erb (0.8ms)
Rendered /Users/alexander/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered /Users/alexander/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (56.3ms)
...和bundle exec rake routes
:
Prefix Verb URI Pattern Controller#Action
root GET / welcome#index
Portfolio GET /Portfolio(.:format) my_work#index
GET /Posts/:id(.:format) posts#with_id
Contact GET /Contact(.:format) contact#index
Contacted GET /Contacted(.:format) contact#contacted
Manage GET /Manage(.:format) manage#index
Manage_Create GET /Manage/Create(.:format) manage#create
Manage_Bye GET /Manage/Bye(.:format) manage#bye
Manage_Logout GET /Manage/Logout(.:format) manage#logout
GET /404(.:format) problems#_404
GET /422(.:format) problems#_422
GET /500(.:format) problems#_500
POST /Contact(.:format) contact#send_message
POST /Manage(.:format) manage#index
POST /Manage/Create(.:format) manage#create
POST /Manage/Logout(.:format) manage#logout
/404(.:format) problems#_404
/422(.:format) problems#_422
/500(.:format) problems#_500
routes.rb
见于nano:
答案 0 :(得分:1)
您正在编辑routes.rb
文件,该文件不是要编辑的文件(config/routes.rb
)
正如@sevenseacat所提到的,请检查http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default,了解有关正确定义路线的方法的一些指导。