[英]How to add a custom column which is not present in table in active admin in rails?
in my rails application, i have installed active admin
. 在我的rails应用程序中,我已经安装了
active admin
。 in users index
page, by default, all columns
are getting displayed(User table columns). 在
users index
页面中,默认情况下,将显示all columns
(用户表列)。 I want to add a custom column called "become user" in this users index view
(which is not a column in User's table). 我想
custom column called "become user" in this users index view
添加一个custom column called "become user" in this users index view
的custom column called "become user" in this users index view
(该列不是用户表中的列)。 under this column
i want to display user name
as a hyperlink
. 在此
column
我想将user name
显示为hyperlink
。 up on clicking of that link the admin
will be logged in to that particular user account. 点击该链接,
admin
将登录该特定用户帐户。 in order to implement this switching feature, i am using switch user
gem. 为了实现这个切换功能,我正在使用
switch user
gem。 how to customise this view in Active Admin
? 如何在
Active Admin
自定义此视图? and how to generate a link for all users in 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
You need to go with approach, that is called virtual attribute in your model: 您需要使用方法,即在模型中称为虚拟属性:
class User < ApplicationRecord
def become_user
"I am a virtual attribute of this user"
end
end
Then add it to your ActiveAdmin setup 然后将其添加到ActiveAdmin设置中
PS: check this for some additional details: Is there an easier way of creating/choosing related data with ActiveAdmin? PS:查看此更多详细信息: 是否有更简单的方法可以使用ActiveAdmin创建/选择相关数据?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.