我有以下幾點:如何爲包含助手的資源創建單一的GET路徑?
routes.rb
resources :splashes, only: [:index, :create, :destroy]
get '/splash', to: 'splashes#index'
>rake routes | grep splash
splashes GET /splashes(.:format) splashes#index
POST /splashes(.:format) splashes#create
splash DELETE /splashes/:id(.:format) splashes#destroy
GET /splash(.:format) splashes#index
但是,當我嘗試使用splash_url
,它產生http://localhost:3000/splashes/1
。
我試圖
get '/splash', to: 'splashes#index', as: 'splash'
但它給
rake routes | grep splash
rake aborted!
ArgumentError: Invalid route name, already in use: 'splash' You may have defined two routes with the same name using the:as
option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created withresources
as explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
我試圖用奇異resource
,但它不產生#index
動作,你不能刪除特定飛濺行。
嘗試改變'資源:飛濺,只有:[:指數, :create,:destroy]'to'resources:splashes,only:[:create,:destroy]' – Pavan
首先,我沒有理解使用* singular資源* **資源集合** – Pavan
@Pavan第1條評論:這並沒有爲GET路徑創建一個'* _url'助手。第2條評論:這是一個_splash_頁面,一個_landing page_。飛濺對人類或營銷者來說沒有意義,但這就是表格和控制器的命名方式。這是爲了領導一代。沒有記錄將被顯示。 – Chloe