使用button_to找不到Ruby on Rails Route,但没有找到link_to

时间:2013-10-29 16:48:46

标签: ruby-on-rails routing link-to button-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阻止通话' 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:in tagged' activesupport(4.0.0)lib / active_support / tagged_logging.rb:67:in tagged' railties (4.0.0) lib/rails/rack/logger.rb:21:in call' 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' rack(1.5.2)lib / rack / runtime.rb:17:in call' activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in call' rack(1.5.2)lib / rack / lock.rb:17:in call' actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in call' railties(4.0.0)lib / rails / engine.rb:511:in call' railties (4.0.0) lib/rails/application.rb:97:in call' passenger(4.0.21)lib / phusion_passenger / rack / 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' passenger(4.0.21)lib / phusion_passenger / request_handler / thread_handler.rb:108:在main_loop' passenger (4.0.21) lib/phusion_passenger/request_handler.rb:441:in块中(3级)在start_threads'

路线

路线优先从上到下匹配

Helper HTTP Verb Path Controller#Action 路径/网址
welcome_index_path GET(/:locale)/welcome(.:format)welcome #index POST(/:locale)/welcome(.:format)welcome #create new_welcome_path GET(/:locale)/welcome/new(.:format)welcome#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#destroy restaurants_path GET(/:locale)/restaurants(.:format)restaurants #index POST(/:locale)/restaurants(.:format)餐馆#create new_restaurant_path GET(/:locale)/restaurants/new(.:format)restaurants#new edit_restaurant_path GET(/:locale)/restaurants/:id/edit(.:format)restaurants#edit restaurant_path GET(/:locale)/restaurants/:id(.:format)restaurants#show PATCH(/:locale)/restaurants/:id(.:format)restaurants#update PUT(/:locale)/restaurants/:id(.:format)餐厅#update DELETE(/:locale)/restaurants/:id(.:format)restaurant#destroy root_path GET / welcome #index

1 个答案:

答案 0 :(得分:2)

默认情况下,button_to会在link_to获取后发布帖子。所以你想要这个

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