繁体   English   中英

如何在rails中的活动管理员中添加表中不存在的自定义列?

[英]How to add a custom column which is not present in table in active admin in rails?

在我的rails应用程序中,我已经安装了active admin users index页面中,默认情况下,将显示all columns (用户表列)。 我想custom column called "become user" in this users index view添加一个custom column called "become user" in this users index viewcustom column called "become user" in this users index view (该列不是用户表中的列)。 在此column我想将user name显示为hyperlink 点击该链接, admin将登录该特定用户帐户。 为了实现这个切换功能,我正在使用switch user gem。 如何在Active Admin自定义此视图? 以及如何为活动管理员中的所有用户生成链接

ActiveAdmin.register User do

  permit_params do
    permitted = [:email, :fname, :lname, :phone]
    #   permitted << :other if resource.something?
    #   permitted
end

  # Filterable attributes on the index screen
  filter :email
  filter :fname
  filter :lname
  filter :phone
  filter :current_sign_in_at
  filter :created_at


  # Customize columns displayed on the index screen in the table
  index do
    selectable_column
    id_column
    column :email
    column :fname
    column :lname
    column :phone
    column :current_sign_in_at
    # column :sign_in_count
    column :created_at

    # actions
  end

  form do |f|
    inputs 'Details' do
      input :email
      input :password
      input :fname
      input :lname
      input :phone
    end
    actions
  end

  controller do
  end

end

您需要使用方法,即在模型中称为虚拟属性:

class User < ApplicationRecord
  def become_user
    "I am a virtual attribute of this user"
  end
end

然后将其添加到ActiveAdmin设置中

PS:查看此更多详细信息: 是否有更简单的方法可以使用ActiveAdmin创建/选择相关数据?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM