Created
November 16, 2010 14:11
-
-
Save ernie/701856 to your computer and use it in GitHub Desktop.
A really evil trick to get at the wrapped AR model in a class method
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
def initialize(base_or_relation, opts = {}) | |
@relation = base_or_relation.scoped | |
@base = @relation.klass | |
@search_key = opts[:search_key] ? opts[:search_key].to_s : 'search' | |
@join_dependency = build_join_dependency | |
@search_attributes = {} | |
@errors = ActiveModel::Errors.new(self) | |
singleton_class.instance_eval "def base; #{@base} end" | |
end | |
# We need the base at the singleton_class level to play nice with i18n. | |
# If anyone's got a less evil solution than this, I'm all ears. | |
def class | |
singleton_class | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
90 days is enough to think about what you've done and how you can do it better. No one deserves a permanent condemnation.