Skip to content

Instantly share code, notes, and snippets.

@raedatoui
Created March 17, 2012 07:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raedatoui/2055952 to your computer and use it in GitHub Desktop.
Save raedatoui/2055952 to your computer and use it in GitHub Desktop.
active admin sort by association
### Model
class ModelA < ActiveRecord::Base
has_many :modelb
end
class ModelB < ActiveRecord::Base
belongs_to :modela
has_many :modelc
end
class ModelC < ActiveRecord::Base
belongs_to :modelb
has_one :modela, :through => :modelb
end
### active admin side
ActiveAdmin.register ModelC do
scope :joined, :default => true do |modelcs|
modelcs.includes [:modelb]
modelcs.includes [:modela]
end
index do
column :modelb, :sortable => :'modelb.title' do |modelc|
link_to modelc.modelb.title, admin_modelb_path(modelc.modelb) unless modelc.modelb.nil?
end
column :modela, :sortable => :'modela.title' do |poi|
link_to modelc.modelb.modela.title, admin_park_path(modelc.modelb.modela) unless modelc.modelb.nil? || modelc.modelb.modela.nil?
end
end
@arthurduarte1
Copy link

Any idea? It doesn't work for me. =/
Thanks at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment