簡體   English   中英

如何在Rails的腳手架資源中添加路線

[英]How to add a route in a scaffold resource in Rails

我使用了腳手架,並且想在routes.rb中的資源中添加新的路由。

但是我想發送不帶id參數的鏈接

我想訪問index2.html.erb,就像訪問index.html.erb的fleamarkets_path一樣。

的routes.rb

resources :fleamarkets do
  member do
    get :index
  end
end

默認耙線

fleamarkets GET    /fleamarkets(.:format)            fleamarkets#index

耙路

index2_fleamarket GET    /fleamarkets/:id/index2(.:format) fleamarkets#index2

然后,您需要使用collection而不是member

resources :fleamarkets do
  collection do
    get :index2
  end
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM