如果我把這個在route.rb get '/products/:id', to: 'products#edit'
編輯操作應該被調用時url格式爲/patients/:id
這是否意味着它將被重定向到編輯頁面?我試過這個,它不是重定向。從代碼導軌生成路徑和URL
這是我的耙路輸出
admin GET /admin(.:format) {:action=>"index", :controller=>"admin"}
GET /products/:id(.:format) {:controller=>"products", :action=>"edit"}
login GET /login(.:format) {:action=>"new", :controller=>"sessions"}
POST /login(.:format) {:action=>"create", :controller=>"sessions"}
logout DELETE /logout(.:format) {:action=>"destroy", :controller=>"sessions"}
users GET (/:locale)/users(.:format) {:action=>"index", :controller=>"users"}
POST (/:locale)/users(.:format) {:action=>"create", :controller=>"users"}
new_user GET (/:locale)/users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET (/:locale)/users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET (/:locale)/users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT (/:locale)/users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE (/:locale)/users/:id(.:format) {:action=>"destroy", :controller=>"users"}
orders GET (/:locale)/orders(.:format) {:action=>"index", :controller=>"orders"}
POST (/:locale)/orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET (/:locale)/orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET (/:locale)/orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET (/:locale)/orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT (/:locale)/orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE (/:locale)/orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
line_items GET (/:locale)/line_items(.:format) {:action=>"index", :controller=>"line_items"}
POST (/:locale)/line_items(.:format) {:action=>"create", :controller=>"line_items"}
new_line_item GET (/:locale)/line_items/new(.:format) {:action=>"new", :controller=>"line_items"}
edit_line_item GET (/:locale)/line_items/:id/edit(.:format) {:action=>"edit", :controller=>"line_items"}
line_item GET (/:locale)/line_items/:id(.:format) {:action=>"show", :controller=>"line_items"}
PUT (/:locale)/line_items/:id(.:format) {:action=>"update", :controller=>"line_items"}
DELETE (/:locale)/line_items/:id(.:format) {:action=>"destroy", :controller=>"line_items"}
carts GET (/:locale)/carts(.:format) {:action=>"index", :controller=>"carts"}
POST (/:locale)/carts(.:format) {:action=>"create", :controller=>"carts"}
new_cart GET (/:locale)/carts/new(.:format) {:action=>"new", :controller=>"carts"}
edit_cart GET (/:locale)/carts/:id/edit(.:format) {:action=>"edit", :controller=>"carts"}
cart GET (/:locale)/carts/:id(.:format) {:action=>"show", :controller=>"carts"}
PUT (/:locale)/carts/:id(.:format) {:action=>"update", :controller=>"carts"}
DELETE (/:locale)/carts/:id(.:format) {:action=>"destroy", :controller=>"carts"}
who_bought_product GET (/:locale)/products/:id/who_bought(.:format) {:action=>"who_bought", :controller=>"products"}
products GET (/:locale)/products(.:format) {:action=>"index", :controller=>"products"}
POST (/:locale)/products(.:format) {:action=>"create", :controller=>"products"}
new_product GET (/:locale)/products/new(.:format) {:action=>"new", :controller=>"products"}
edit_product GET (/:locale)/products/:id/edit(.:format) {:action=>"edit", :controller=>"products"}
product GET (/:locale)/products/:id(.:format) {:action=>"show", :controller=>"products"}
PUT (/:locale)/products/:id(.:format) {:action=>"update", :controller=>"products"}
DELETE (/:locale)/products/:id(.:format) {:action=>"destroy", :controller=>"products"}
store /(:locale)(.:format) {:controller=>"store", :action=>"index"}
你怎麼重定向到編輯頁面? 'redirect_to'或'link_to'? – swapab
這不是重定向。如果您通過使用redirect_to從一個動作向另一個動作發送請求而不是其調用重定向,那麼您正在嘗試的是將此URL映射到患者控制器的編輯動作 –
我鼓勵您閱讀[rails routing](http:// guides .rubyonrails.org/routing.html) – swapab