是否有建立一個更好的方法下面這兩條路線:建立路線的更好方法?導軌
post '/song:id/favorite', to: 'songs#favorite', as: :favorite
delete '/song:id/favorite', to: 'favorites#destroy', as: :destroy
這裏都是我的路線:
Rails.application.routes.draw do
root "home#index"
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
post '/song:id/favorite', to: 'songs#favorite', as: :favorite
delete '/song:id/favorite', to: 'favorites#destroy', as: :destroy
namespace :admin do
resource :dashboard, only: [:show]
end
resources :users, only: [:new, :create]
resources :playlists
resources :genres
resources :albums
resources :artists
resources :playlist_songs
resources :favorites
resources :songs
end
在我看來,你可以嘗試實現像在[這個答案](https://stackoverflow.com/a/24306086/6873497) 。我認爲你現在的設計可以調整爲使用簡單的CRUD操作。 – matiss
謝謝@matiss!我的設計是根據你的建議創建的:)我的問題基本上是,有什麼問題,我的當前路線是如何設置的,還是有更好的方法來做到這一點? p.s我是菜鳥 – Kurta