嗨我在我的项目中使用活动的admin gem
我无法在主动管理信息中心看到退出链接。
我只为用户表的所有用户提供了一个表
的routes.rb
Rails.application.routes.draw do
ActiveAdmin.routes(self)
devise_for :users, controllers: { sessions: 'sessions' , :registrations => "registrations" }
namespace :api do
namespace :v1 do
resources :users
end
end
resources :users
devise_scope :user do
match '/users/sign_in', to: 'sessions#create', via: :post
#registration seems to much cooler for authenticable and other stuff
#match 'api/v1/users' , to: 'registrations#create' , via: :post
end
end
在/ admin / dashboard中
ActiveAdmin.register_page "Dashboard" do
menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }
content title: proc{ I18n.t("active_admin.dashboard") } do
div class: "blank_slate_container", id: "dashboard_default_message" do
span class: "blank_slate" do
span I18n.t("active_admin.dashboard_welcome.welcome")
small I18n.t("active_admin.dashboard_welcome.call_to_action")
end
end
end # content
end
这就是我的管理员/用户的样子
ActiveAdmin.register User do
#permit_params :email , :role_ids ,:password
permit_params :email , :password ,:role_ids => []
form do |f|
f.inputs "Users" do
f.input :email
f.input :password
f.input :roles, as: :select, multiple: false, collection: Role.all
end
f.actions
end
show do
attributes_table do
row :email
row :encrypted_password
row :reset_password_token
row :reset_password_sent_at
row :remember_created_at
row :sign_in_count
row :current_sign_in_at
row :last_sign_in_at
row :current_sign_in_ip
row :last_sign_in_ip
row :created_at
row :updated_at
row :authentication_token
row :roles do | user |
user.roles.first.name unless user.roles.blank?
end
end
end
index do
column :email
#column :encrypted_password
#column :reset_password_token
#column :reset_password_sent_at
column :remember_created_at
column :sign_in_count
column :current_sign_in_at
column :last_sign_in_at
#column :current_sign_in_ip
#column :last_sign_in_ip
column :created_at
column :updated_at
#column :authentication_token
column :roles do | user |
user.roles.first.name unless user.roles.blank?
end
actions
end
controller do
def create
@user = User.new(user_params)
binding.pry
add_roles(@user)
create!
end
def update
add_roles(resource)
update!(user_params)
end
private
def add_roles(resource)
resource.roles = []
params[:user][:role_ids].each {
|r| resource.add_role(Role.find(r).name.downcase!) unless r.blank?
}
end
def user_params
params.require(:user).permit(:email, :password, :role_ids => [])
end
end
end
答案 0 :(得分:5)
可能是因为它找不到注销路径或当前用户。 尝试修改active_admin初始值设定项:
config.logout_link_path = :logout_path #Put your logout path here
config.logout_link_method = :delete
config.current_user_method = :current_user