Created
March 17, 2012 07:05
-
-
Save raedatoui/2055952 to your computer and use it in GitHub Desktop.
active admin sort by association
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any idea? It doesn't work for me. =/
Thanks at all.