ruby-on-rails - 如何设计两个不同的门户?
问题描述
这是我的路线.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
但无法找到一个很好的方法让它在staff
and之间进行区分franchisee
。
解决方案
推荐阅读
- java - 从 Rest 服务返回 JSON 响应?
- c# - 使用 JsonConvert 反序列化单个 DateTime 对象
- c++ - C++ ostream_withassign 与 << 运算符编译错误
- r - 新数据表中的计算列而不更改原始数据表
- android - Android 签名的 APK 在 Android 中不显示地图
- android - FlatList Sticky 标头在 ScrollView 中不起作用?
- ios - 如何使用 ARKit 用手指拖动 SCNode 而不考虑轴?
- http - 为什么建议使用 ctx 作为第一个参数?
- php - 未从 Codeigniter 中的数据库接收到数据
- javascript - FullCalendar.io。无法呈现后台事件