Ray
Ray

Reputation: 349

Rails ActiveAdmin showing attributes from different model

ActiveAdmin.register User do
 index do
   column :email
   column :first_name
   column :surname
 end
end

app/models/user.rb

  has_many :tasks

app/models/task.rb

  belongs_to :user

I have all the attributes in the User model. Is it possible to call those attributes in the Task model. I tried to look up for it but couldn't find anything suitable. For example:

ActiveAdmin.register Task do
  index do
   column :email
   column :first_name
   column :surname
 end
end

Upvotes: 0

Views: 728

Answers (1)

Van Huy
Van Huy

Reputation: 1627

Yes, you can! For example:

ActiveAdmin.register Task do
  index do
    column "Email" do |task|
      task.user.email
    end
    column "First name" do |task|
      task.user.first_name
    end
  end
end

Upvotes: 1

Related Questions