Skip to content

Instantly share code, notes, and snippets.

@phinze
Created July 22, 2009 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phinze/152057 to your computer and use it in GitHub Desktop.
Save phinze/152057 to your computer and use it in GitHub Desktop.
# vendor/plugins/has_associated_data
def ModelFoo < ActiveRecord::Base
has_associated_data do |a|
a.building :through => [:animal_location]
a.method_i_want_exposed :through => [:association, :chain, :to, :get, :there], :attr => :if_different_than_exposed_method
end
def building
end
def building=
end
named_scope :sorted_by_building_{asc/desc}
named_scope :sorted_by_{column}_{asc/desc}
end
## what does it look like in the controller
class FooController < ActionController::Base
def index
@collection_i_want_listed = FooModel.sorted_by_params(params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment