是否有建立一个更好的方法下面这两条路线:建立路线的更好方法?导轨
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