I have a problem with routing in my app, but i do not understand why. I hope someone can explain me why this is so.
thank you very much for help.
<%= 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' %>
The link_to code routes correctly to the needed restaurant, but the button_to produces the following:
No route matches [POST] "/de/restaurants/526fe01e65617271ea000000"
Trace:
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'
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:in main_loop'
passenger (4.0.21) lib/phusion_passenger/request_handler.rb:441:in
block (3 levels) in start_threads'
Routes
Routes match in priority from top to bottom
Helper HTTP Verb Path Controller#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) 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) restaurants#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) restaurants#update
DELETE (/:locale)/restaurants/:id(.:format) restaurants#destroy
root_path GET / welcome#index
By default, button_to
does a post while link_to
does a get. So you want this
<%= button_to 'Show', restaurant_path(restaurant), :id => 'button_show_restaurant', :class => 'btn btn-success', :method => :get %>