I have a model (Document) which presents a non-table-column attribute
"review_required?". I need to be able to filter the input to hobo_index
and/or table-plus such that only the records with a true value are
displayed.
The review_required? attribute is a relatively complex function of the
children of the Document model that would be extremely tedious and
error-prone to replace with a pre-calculated table column.
What works:
hobo_index Document
and
<table-plus fields="this, review_required?" without-search-form param/>
Produces a nice list of documents
Document Review Required
doc 1 Yes
doc 3 No
doc 4 No
doc 6 Yes
etc.
So I am sure the review_required? attribute works.
What doesn't work:
I have tried numerous ways of filtering the output of Document.
Document.find(:all, :conditions=> ... ) doesn't work because
review_required is not field in the table.
Document.review_required(true) doesn't work because it doesn't recognize
the method review_required (its there).
I have tried many variations on this theme, including adding a second
method review_required without the ?, but all fail for the same reason.
Document.apply_scopes(:review_required => true) same failure, can't find
review_required. Grasping at straws here.
I used the output of Document.find(:all) to create an array of the
records that meet the criterion, but hobo_index fails because the array
is not a finder.
Help anyone! :-[
Don Z.
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
> Hi Tiago,
>
> hobo_index Document.all.map { |d| d.review_required? }
>
> undefined method `default_order' for #<Array:0xb38ca844>
>
> I think this was the same error I got during one of the iterations where I manually filtered the output of Document.find(:all) into an array.
>
> Don Z.
The issue is in find_or_paginate - it's trying to figure out what order to sort the results in and breaking as a result. We should probably check responds_to?(:default_order) in there.
For now, you're probably better off just setting 'this' explicitly - hobo_index isn't doing much else for you:
def some_method
self.this = ...build an arbitrary collection...
end
If you're using table-plus, you'll also want to give the array the ability to respond to member_class, or you'll get more errors:
def some_method
ary = ...build an arbitrary collection...
def ary.member_class
SomeObject
end
self.this = ary
end
--Matt Jones
undefined method `default_order' for #<Class:0xb543f890>Can you post the complete backtrace?
--Matt Jones
> https://gist.github.com/1132324
>
> Not a whole lot in there
Hmmm - not sure where the rest of it is going. It looks like the most likely culprit in this case is a select-one, which ends up calling 'this_field_reflection.klass.default_order'.
The problem is that AR (last I checked - this was back in 2.3) is returning a funky proxy-flavored object instead of a standard class. I would make sure that the form is skipping the polymorphic association field.
--Matt Jones