user1951582
user1951582

Reputation: 1

Routes not matching

I am not able to call an action in a controller using link_to.

I have a route defined in my routes.rb file to a reservation controller (as detailed below) and I want to access the 'create_commercial' action in the 'my/reservations' controller.

So if I draw the routes using rake routes | grep 'reservation'

                         visitor_my_reservations GET    (/:locale)/my/reservations/visitor(.:format)                               {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"visitor"}
           create_commercial_my_reservations POST   (/:locale)/my/reservations/create_commercial(.:format)                     {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"create_commercial"}
                      confirm_my_reservation PUT    (/:locale)/my/reservations/:id/confirm(.:format)                           {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"confirm"}
                          pay_my_reservation GET    (/:locale)/my/reservations/:id/pay(.:format)                               {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"pay"}
              payment_success_my_reservation GET    (/:locale)/my/reservations/:id/payment_success(.:format)                   {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"payment_success"}
               payment_cancel_my_reservation GET    (/:locale)/my/reservations/:id/payment_cancel(.:format)                    {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"payment_cancel"}
                             my_reservations POST   (/:locale)/my/reservations(.:format)                                       {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"create"}
                          new_my_reservation GET    (/:locale)/my/reservations/new(.:format)                                   {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"new"}
                         edit_my_reservation GET    (/:locale)/my/reservations/:id/edit(.:format)                              {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"edit"}
                              my_reservation GET    (/:locale)/my/reservations/:id(.:format)                                   {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"show"}
                                             PUT    (/:locale)/my/reservations/:id(.:format)                                   {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"update"}
                                             DELETE (/:locale)/my/reservations/:id(.:format)                                   {:locale=>/en|en-US|en-GB/, :controller=>"my/reservations", :action=>"destroy"}
                   show_test_my_reservations GET    /test/my/reservations/show(.:format)                                       {:controller=>"test/my/reservations", :action=>"show"}
                     new_test_my_reservation GET    /test/my/reservations/new(.:format)                                        {:controller=>"test/my/reservations", :action=>"new"}

so i then try to:-

<td><%= link_to 'book', create_commercial_my_reservations_path %></td>

I also try this:-

<%= link_to('Book', {:controller => 'my/reservations', :action => 'create_commercial', :method => :post}) %>

and I see in the console window for both options:-

Started GET "/en-GB/my/reservations/create_commercial" for 127.0.0.1 at Sat Jan 05 18:29:30 +0000 2013
  Processing by My::ReservationsController#show as HTML
  Parameters: {"id"=>"create_commercial", "locale"=>"en-GB"}
Geokit is using the domain: localhost

the URL is right, but action 'show' is being called, and method is 'get', not 'post'.

Does anybody have any idea what I could be doing wrong... Guidance very much appreciated.

Upvotes: 0

Views: 89

Answers (1)

Philip Hallstrom
Philip Hallstrom

Reputation: 19879

Try...

<%= link_to 'book', create_commercial_my_reservations_path, :method => :post %>

With the caveat that it seems a little odd to be linking to a #create action instead of a #new action, but I don't know your app...

Upvotes: 1

Related Questions