Ruby on Rails Route 在 button_to 中找不到,但在link_to中找不到



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

非常感谢您的帮助。

<%= 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:in call'railties (4.0.0) lib/rails/rack/logger.rb:38:in call_app' railties (4.0.0) lib/rails/rack/logger.rb:21:in block in call'活动支持 (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:in标记'activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in tagged' railties (4.0.0) lib/rails/rack/logger.rb:21:in调用'ActionPack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.5.2) lib/rack/methodoverride.rb:21:in call'机架 (1.5.2) lib/rack/runtime.rb:17:in call' activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in调用'机架 (1.5.2) lib/rack/lock.rb:17:in call' actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in调用'railties(4.0.0) lib/rails/engine.rb:511:in call' railties (4.0.0) lib/rails/application.rb:97:in call'乘客 (4.0.21) lib/phusion_passenger/机架/thread_handler_extension.rb:77:in process_request' passenger (4.0.21) lib/phusion_passenger/request_handler/thread_handler.rb:140:in accept_and_process_next_request'乘客 (4.0.21) lib/phusion_passenger/request_handler/thread_handler.rb:108:在start_threads main_loop' passenger (4.0.21) lib/phusion_passenger/request_handler.rb:441:in块(3 层)中

路线

路由从上到下的优先级匹配

帮助程序 HTTP 谓词路径控制器#操作路径/网址
welcome_index_path GET (/:locale)/welcome(.:format) welcome#indexPOST (/:locale)/welcome(.:format) welcome#createnew_welcome_path GET (/:locale)/welcome/new(.:format) welcome#newedit_welcome_path GET (/:locale)/welcome/:id/edit(.:format) welcome#editwelcome_path GET (/:locale)/welcome/:id(.:format) welcome#show补丁 (/:locale)/welcome/:id(.:format) 欢迎#更新PUT (/:locale)/welcome/:id(.:format) welcome#update删除 (/:locale)/welcome/:id(.:format) welcome#destroyrestaurants_path GET (/:locale)/restaurants(.:format) restaurants#indexPOST (/:locale)/restaurants(.:format) restaurants#createnew_restaurant_path GET (/:locale)/restaurants/new(.:format) restaurants#newedit_restaurant_path GET (/:locale)/restaurants/:id/edit(.:format) restaurants#editrestaurant_path GET (/:locale)/restaurants/:id(.:format) restaurants#showPATCH (/:locale)/restaurants/:id(.:format) restaurants#updatePUT (/:locale)/restaurants/:id(.:format) restaurants#updateDELETE (/:locale)/restaurants/:id(.:format) restaurants#destroyroot_path 获取/欢迎#索引

默认情况下,button_to做帖子,而link_to做一个get。所以你想要这个

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

相关内容

  • 没有找到相关文章

最新更新