I want to use the results of an instance method on the model (setup as a virtual column in AS) to sort. The instance method filters a collection of child objects based on parameters passed by the parent. Not sure if a proc would work here, and what the syntax would look like if it would. This controller code does not cause errors, but it also does not sort properly.
class Challenge < ActiveRecord::Base
...
has_and_belongs_to_many :users
...
end
class user < ActiveRecord::Base
has_and_belongs_to_many :challenges
...
def training_sessions_by_challenge(challenge)
#returns filtered collection of sessions that meet the criteria of the supplied challenge instance
end
end
class UsersController < ApplicationController
before_filter :customize_config
active_scaffold do |config|
...
end
protected
def customize_config
if active_scaffold_constraints[:challenges]
@challenge = Challenge.find(active_scaffold_constraints[:challenges].to_i
active_scaffold_config.columns[:training_sessions_count].sort_by :method => "training_sessions_by_challenge(@challenge).count"
end
end