1

Using Rails 4 and the latest Active Admin. I am trying to build an Active Admin index page for my Submission model. In short, it's a contest app where one submission has many scores. In the Score model, there is a field called :total_score where a judge inputs their score for that entry.

So naturally, to find the final score of the submission I need to average all children scores:

# In my Submission model
def calculate_final_score
  self.scores.average(:total_score)
end

Which then returns the averaged number. Naturally, I want to display this number in my Submission Active Admin index page. I use this code (it's a table-format index page):

column "Score", sortable: :calculate_final_score do |submission|
  submission.calculate_final_score
end

While it displays the value fine, it does not know how to sort this custom method. Like, if I tell it to sort by that column descending, it will order it 10.0, 6.0, 3.75, 8.0, 9.0, etc. How do I get it to sort properly?

Secondly, it also does not know how to filter this custom method column. I put in the code filter :calculate_final_score but it does not display that filter on the page at all. Is this a limitation of Active Admin or is there a way to make that filter work properly? Thanks for any help.

Rachel9494
  • 849
  • 1
  • 7
  • 27

1 Answers1

0

this is a duplicate of the following questions:

nevertheless, those questions don't have a real answer to what's happening in active_admin and why this stuff is not working.

the reason for this can be found in ActiveAdmin::OrderClause.

it only supports columns on the model and columns on associated models.

Community
  • 1
  • 1
phoet
  • 18,688
  • 4
  • 46
  • 74
  • Thanks, I guess I'll have to remove that functionality for now and hope it'll work in the CSV export I guess. I did see at least one of those questions before but, you're right, that wasn't the most optimal solution. – Rachel9494 Mar 21 '14 at 20:08