0

我的应用程序中的路由有问题,但我不明白为什么。我希望有人能解释我为什么会这样。

非常感谢您的帮助。

<%= link_to 'Show', restaurant_path(restaurant), :id => 'button_show_restaurant', :class => 'btn btn-success' %> 

<%= button_to 'Show', restaurant_path(restaurant), :id => 'button_show_restaurant', :class => 'btn btn-success' %>

link_to 代码正确路由到所需的餐厅,但 button_to 产生以下内容:

没有路线匹配 [POST] "/de/restaurants/526fe01e65617271ea000000" 跟踪:actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:incall' railties (4.0.0) lib/rails/rack/logger .rb:38:in call_app' railties (4.0.0) lib/rails/rack/logger.rb:21:inblock in call'activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in block in tagged' activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:intagged' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in tagged' railties (4.0.0) lib/rails/rack/logger.rb:21:incall' actionpack ( 4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.5.2) lib/rack/methodoverride.rb:21:incall' rack (1.5.2) lib/rack/runtime.rb:17:in call' activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:incall' rack (1.5.2) lib/rack/lock. rb:17:in call' actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:incall' railties (4.0.0) lib/rails/engine.rb:511:in call' railties (4.0.0) lib/rails/application.rb:97:incall'passenger (4.0.21) lib/phusion_passenger/rack/thread_handler_extension.rb:77:inprocess_request' passenger (4.0.21) lib/phusion_passenger/request_handler/thread_handler.rb:140:inaccept_and_process_next_request' 乘客 (4.0.21) lib/phusion_passenger/request_handler/thread_handler.rb:108:in main_loop' passenger (4.0.21) lib/phusion_passenger/request_handler.rb:441:inblock (3 levels) in start_threads'

路线

路由从上到下优先匹配

Helper HTTP 动词路径控制器#Action Path / Url
welcome_index_path GET (/:locale)/welcome(.:format) welcome#index POST (/:locale)/welcome(.:format) welcome#create new_welcome_path GET (/:locale)/welcome/new(.:format) 欢迎#new edit_welcome_path GET (/:locale)/welcome/:id/edit(.:format) Welcome#edit welcome_path GET (/:locale)/welcome/:id(.:format) Welcome#show PATCH (/:locale) /welcome/:id(.:format) welcome#update PUT (/:locale)/welcome/:id(.:format) welcome#update DELETE (/:locale)/welcome/:id(.:format) Welcome#销毁餐厅路径 GET (/:locale)/restaurants(.:format) 餐厅#index POST (/:locale)/restaurants(.:format) 餐厅#create new_restaurant_path GET (/:locale)/restaurants/new(.:format)餐厅#new edit_restaurant_path GET (/:locale)/restaurants/:id/edit(.:格式) 餐厅#edit restaurant_path GET (/:locale)/restaurants/:id(.:format) 餐厅#show PATCH (/:locale)/restaurants/:id(.:format) 餐厅#update PUT (/:locale) /restaurants/:id(.:format) 餐厅#update DELETE (/:locale)/restaurants/:id(.:format) 餐厅#destroy root_path GET /welcome#index

4

1 回答 1

2

默认情况下,在获取button_to信息的同时发布信息link_to。所以你想要这个

<%= button_to 'Show', restaurant_path(restaurant), :id => 'button_show_restaurant', :class => 'btn btn-success', :method => :get %>
于 2013-10-29T16:56:20.403 回答