Ruby on rails Rails 6-如何替换路由URI模式的一部分?

Ruby on rails Rails 6-如何替换路由URI模式的一部分?,ruby-on-rails,ruby-on-rails-6,Ruby On Rails,Ruby On Rails 6,如果用户调用URLapplication.com,它将重定向到application.com/account/1/sessions/new 我想将重定向URL替换为application.com/sessions/new(host/account/:id->host) routes.rb Rails.application.routes.draw do get '/', to: 'dashboard#index' resources :accounts do resources

如果用户调用URLapplication.com,它将重定向到application.com/account/1/sessions/new

我想将重定向URL替换为application.com/sessions/new(host/account/:id->host)

routes.rb

Rails.application.routes.draw do

get '/', to: 'dashboard#index'

  resources :accounts do
    resources :sessions
  end

end
class ApplicationController < ActionController::Base

...
  #account has a column host to be identified if the user called URL host belongs to an existing account
  def get_account_id
    account_id = Account.find_by(host: request.host).id
  end

  def authorize
    if session[:user_id]
      redirect_to new_account_session_path(get_account_id)
      return
    end
  end

end
铁路线路:

new_account_session GET    /accounts/:account_id/sessions/new(.:format)      sessions#new
应用程序\u控制器.rb

Rails.application.routes.draw do

get '/', to: 'dashboard#index'

  resources :accounts do
    resources :sessions
  end

end
class ApplicationController < ActionController::Base

...
  #account has a column host to be identified if the user called URL host belongs to an existing account
  def get_account_id
    account_id = Account.find_by(host: request.host).id
  end

  def authorize
    if session[:user_id]
      redirect_to new_account_session_path(get_account_id)
      return
    end
  end

end
class ApplicationController
从内部:帐户中删除:会话

resources :accounts
resources :sessions
当您这样嵌套资源时,您基本上是说会话的所有路由都应该链接到一个帐户