2013-01-05 196 views
0

我不能調用使用的link_to在控制器的動作。不匹配路由

我在我的routes.rb文件保留控制器定義的路由(詳見下文),我想訪問在「我的/預訂」控制器「create_commercial」行動。

所以,如果我使用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"} 

繪製的路線,所以我再嘗試: -

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

我也試試這個: -

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

,我在看兩個選項的控制檯窗口: -

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 

的URL是正確的,但行動「秀」被調用,而方法是「得到」,而不是「後」。

是否有人有任何想法我可能是做錯了什麼......指導非常讚賞。

回答

1

的Try ...

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

有了,它似乎有點奇怪被鏈接到#創建行動,而不是#NEW行動的警告,但我不知道你的應用程序...

+0

同樣的事情,我害怕。我會再看看爲什麼我要鏈接到創建操作!乾杯 – user1951582