管理小组管理组织的员工。现在每个组织都有自己的子域:
dms.site.com/admin
fake.site.com/admin
但是我想使用没有子域的Rails命名空间:
scope '/*business' do
devise_for :users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
end
路线:
site.com/dms/admin
site.com/fake/admin
但是ActiveAdmin不了解应该如何建立链接。对于菜单,我这样做了(并且有效):
class ApplicationController < ActionController::Base
before_action :set_default_url_options
...
def set_default_url_options
Rails.application.routes.default_url_options[:business] = current_business.scope
end
...
end
# => site.com/dms/admin/employees
# => site.com/fake/admin/employees
但是我不能教他如何正确地为资源操作建立链接:
ActiveAdmin.register Employee do
...
index do
column :name
actions defaults: true do |manager|
# reset password - ok, but actions for new, edit etc. - no =(
link_to 'Reset password', reset_password_admin_employee_path(manager, business: 'dms'), method: :post
end
end
...
end
我收到此错误:
ActionView::Template::Error (No route matches {:action=>"show", :business=>#<Employee id: 12, email: "jaydon.jones@example.org", name: "Deontae Rowe", role: "employee", position_id: 1, business_id: 1, super_administrator: false, created_at: "2018-08-11 09:18:57", updated_at: "2018-08-11 09:18:57">, :controller=>"admin/employees"}, missing required keys: [:id]):
1: insert_tag renderer_for(:index)
app/admin/users/employees.rb:49:in `block (2 levels) in <main>'