1
のための目に見えない動的な方法私はcurrent_managerのような方法で問題を抱えているが、current_receptionistなど工夫認証
クライアントのための方法をせずに、目に見えないがあります。ルーティングによって発生します。私は名前空間のバックエンドにすべてのタイプの人々(クライアントなし)を配置しました。この名前空間の上に移動すると、すべてのメソッドが利用できます。しかし、私はこの宣言が欲しい:
devise_for :receptionists, :managers...
がバックエンド名前空間にある。
正しい表示方法を使用できるようにコードを変更するにはどうすればよいですか?
class BackendController < ApplicationController
%w(Manager Receptionist Lifeguard Trainer).each do |k|
define_method "current_#{k.underscore}" do
current_person if current_person.is_a?(k.constantize)
end
define_method "authenticate_#{k.underscore}!" do |_opts = {}|
send("current_#{k.underscore}") || not_authorized
end
define_method "#{k.underscore}_signed_in?" do
!send("current_#{k.underscore}").nil?
end
end
end
ルーティング:コントローラ/ backend_controller.rbで
動的メソッド
Rails.application.routes.draw do
devise_for :people, controllers: { sessions: 'devise/sessions' },
skip: [:registrations]
devise_for :clients, skip: :sessions
namespace :backend do
devise_for :receptionists, :managers, :lifeguards, :trainers,
skip: :sessions, controllers: { registrations: 'devise/registrations' }
end
end
誰でも助けてくれますか? –