我有以下路线:
authenticated :user do
scope module: 'admin', path: ':publisher_id' do
get 'settings/general', to: 'publishers#index', as: 'publisher_settings'
post 'settings/general', to: 'publishers#create'
put 'settings/general', to: 'publishers#update'
end
end
然而,第一个
as:
只能使用一次我怎样才能使这适用于所有这些路线我希望他们都为publisher_settings_path
工作 最佳答案
您还可以将as
选项传递给Rails路由中的名称空间和作用域。
# prefix the routing helper name: +sekret_posts_path+ instead of +posts_path+
scope as: "sekret" do
resources :posts
end
来源:https://api.rubyonrails.org/v5.1/classes/ActionDispatch/Routing/Mapper/Scoping.html
我想这也应该行得通
Rails.application.routes.draw do
resources :publishers, only: [:create, :update, :index], path: 'settings/general', as: 'publisher_settings'
end
抓住我
publisher_settings GET /settings/general(.:format) publishers#index
POST /settings/general(.:format) publishers#create
publisher_setting PATCH /settings/general/:id(.:format) publishers#update
PUT /settings/general/:id(.:format) publishers#update
关于ruby-on-rails - 铁路多条路线,与`相同,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53356154/