如何在 Rails 的 ActiveAdmin 中指定 auto-incremented 的列?
How to specify a column which is auto-incremented in ActiveAdmin in Rails?
我在 Rails 5.0 中使用 ActiveAdmin,目前显示的数据如附图所示:
我想用 auto-incremented 列替换 ID 列,
这是我的代码:
index do
id_column // i want to replace this with auto-incremented column
column "Job" do |review|
review.applicant.job.title
end
column "Applicant" do |review|
"#{review.applicant.profile.name}"
end
column :created_at
column "Actions" do |review|
link_to "View", admin_review_path(review)
end
end
希望你给自增序列号。如果您想添加序列号,请尝试以下代码
index do
selectable_column
@index = 30*(((params[:page] || 1).to_i) - 1) #30 needs to set to that what your page size
column :number do
@index +=1
end
column "Job" do |review|
review.applicant.job.title
end
column "Applicant" do |review|
"#{review.applicant.profile.name}"
end
column :created_at
column "Actions" do |review|
link_to "View", admin_review_path(review)
end
end
以上代码内容复制自Numbering items in an ActiveAdmin Report。请参考题目。
ActiveAdmin 有一个 DSL。
index do
selectable_column
index_column
column ...
end
如果你使用旧的 ActiveAdmin 版本,你可以这样做:Numbering items in an ActiveAdmin Report
我在 Rails 5.0 中使用 ActiveAdmin,目前显示的数据如附图所示:
我想用 auto-incremented 列替换 ID 列,
这是我的代码:
index do
id_column // i want to replace this with auto-incremented column
column "Job" do |review|
review.applicant.job.title
end
column "Applicant" do |review|
"#{review.applicant.profile.name}"
end
column :created_at
column "Actions" do |review|
link_to "View", admin_review_path(review)
end
end
希望你给自增序列号。如果您想添加序列号,请尝试以下代码
index do
selectable_column
@index = 30*(((params[:page] || 1).to_i) - 1) #30 needs to set to that what your page size
column :number do
@index +=1
end
column "Job" do |review|
review.applicant.job.title
end
column "Applicant" do |review|
"#{review.applicant.profile.name}"
end
column :created_at
column "Actions" do |review|
link_to "View", admin_review_path(review)
end
end
以上代码内容复制自Numbering items in an ActiveAdmin Report。请参考题目。
ActiveAdmin 有一个 DSL。
index do
selectable_column
index_column
column ...
end
如果你使用旧的 ActiveAdmin 版本,你可以这样做:Numbering items in an ActiveAdmin Report