gpt4 book ai didi

ruby-on-rails - 如何合并路由声明(子域或 token )?

转载 作者:行者123 更新时间:2023-12-04 05:52:53 25 4
gpt4 key购买 nike

我有一个可以通过多种方式访问​​的模型模型:通过子域或 token

  • http://model1.domain.com
  • http://domain.com/j4h7

  • 我有以下路线
    resources :model, :constraints => {:model_id => /[a-zA-Z0-9]{4}/} do
    ... (nested resources...)
    end
    resources :model, :constraints => {:subdomain => /.+/} do
    ... (same as above: nested resources...)
    end

    所以我目前必须复制这两种情况的所有路线。

    有没有办法只声明一次?

    最佳答案

    def nested_routes
    get :some_route
    post :some route
    resources :some_resources
    end

    resources :model, :constraints => {:model_id => /[a-zA-Z0-9]{4}/} do
    nested_routes
    end

    resources :model, :constraints => {:subdomain => /.+/} do
    nested_routes
    end

    相关主题: Rails 3 Routes: DRY members

    关于ruby-on-rails - 如何合并路由声明(子域或 token )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5778848/

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