gpt4 book ai didi

ruby-on-rails - 将 Rails 路线限制为 Action

转载 作者:数据小太阳 更新时间:2023-10-29 07:53:11 26 4
gpt4 key购买 nike

假设我有一个 UsersController,其中包含一个操作 #new。在我的路线文件中,我映射了以下内容:

match 'signup', to: 'users#new'

现在/signup 和/users/new 都可以访问此操作。如何将其限制为仅自定义路由。

如果有人回答了这个问题,我深表歉意,但我是新手。我已经搜索过,但没有找到答案。可能是因为我不知道如何简洁地表达这一点。

最佳答案

您可以从用户资源中免除 new 路由,并将其替换为您的自定义路由:

resources :users, except: [:new]
get 'signup', to: 'users#new', as: "new_user"

导致:

    users GET        /users(.:format)               users#index
POST /users(.:format) users#create
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
new_user GET /signup(.:format) users#new

关于ruby-on-rails - 将 Rails 路线限制为 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17417291/

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