0

link_to を使用してコントローラーでアクションを呼び出すことができません。

routes.rb ファイルで予約コントローラーへのルートを定義しており (詳細は後述)、「my/reservations」コントローラーの「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 は正しいが、アクション 'show' が呼び出されており、メソッドは 'post' ではなく 'get' です。

私が間違っている可能性があることを知っている人はいますか...ガイダンスは非常に高く評価されています。

4

1 に答える 1

1

試す...

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

#new アクションの代わりに #create アクションにリンクするのは少し奇妙に思えるという警告がありますが、あなたのアプリはわかりません...

于 2013-01-05T19:03:22.830 に答える