我无法使用 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”,方法是“get”,而不是“post”。
有没有人知道我可能做错了什么......非常感谢指导。