首页 > 解决方案 > 如何设计两个不同的门户?

问题描述

这是我的路线.rb:

  scope '/staff' do
    authenticated :staff_member do
      root to: 'staff/schedule_entries#index'
    end

    unauthenticated :staff_member do
      root to: 'staff/chains#index'
    end

    scope '/:chain_id', constraints: StaffChainConstraint do
      devise_for :staff_members, path: '', controllers: {
        sessions: "staff/sessions",
        passwords: "staff/passwords",
      }, only: [:sessions, :passwords]
    end
  end

  scope '/franchisee' do
    authenticated :staff_members do
      root to: 'franchisee/locations#edit'
    end

    unauthenticated :staff_members do
      root to: 'franchisee/chains#index'
    end


    scope '/:chain_id', constraints: StaffChainConstraint do
      devise_scope :staff_member do
        get 'sign_in', to: 'franchisee/sessions#new', as: :new_franchisee_session
        post 'sign_in', to: 'franchisee/sessions#create', as: :franchisee_session
      end
    end
  end

我遇到的问题是从页面签名后franchisee/:chain_id/sign_in,它一直重定向到staff/schedule_entries#index而不是franchisee/locations#edit. 我缺少什么来完成这项工作?

编辑:这是我的franchisee/sessions控制器:

# frozen_string_literal: true
module Franchisee
  class SessionsController < Devise::SessionsController
    helper_method :current_brand, :current_chain

    before_action :configure_sign_in_params, only: [:create, :new]

    protected

    def respond_to_on_destroy
      path = if current_admin
        admin_root_path
      else
        after_sign_out_path_for(resource_name)
      end
      redirect_to path
    end

    def current_chain
      @current_chain ||= Chain.find_by!(slug: params[:chain_id])
    end

    def current_brand
      current_chain.brand
    end

    def configure_sign_in_params
      devise_parameter_sanitizer.permit(:sign_in, keys: [:username, :password])
    end

    def set_raven_context
      Raven.tags_context(app: 'franchisee')
      Raven.user_context(
        type: 'franchisee',
        username: params.dig(:staff_member, :username),
        brand_slug: current_brand&.slug,
        chain_slug: params[:chain_id],
      )
    end
  end
end

我确保在从页面提交登录表单时会点击此控制器franchisee/:chain_id/sign_in。我也试图摆弄,after_sign_in_for但无法找到一个很好的方法让它在staffand之间进行区分franchisee

标签: ruby-on-railsdevise

解决方案


推荐阅读