gpt4 book ai didi

ruby-on-rails - Rails 多条路线,相同的 `as`

转载 作者:太空宇宙 更新时间:2023-11-03 16:40:45 25 4
gpt4 key购买 nike

我有以下路线:

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 Routes 中的命名空间和作用域。

# 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 - Rails 多条路线,相同的 `as`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53356154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com