如何在Rails中指定ActiveAdmin中自动递增的列?

时间:2016-10-25 05:04:24

标签: ruby-on-rails activeadmin

我正在使用Rails 5.0中的ActiveAdmin,目前显示的数据如附图所示:

enter image description here

我想将 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

2 个答案:

答案 0 :(得分:1)

我希望你想给出自动增量序列号。如果要添加序列号,请尝试以下代码

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复制上述代码内容。请参阅主题。

答案 1 :(得分:0)

ActiveAdmin有一个DSL。

index do
  selectable_column
  index_column
  column ...
end

我使用旧的ActiveAdmin版本,您可以执行此操作:Numbering items in an ActiveAdmin Report