hobo_index / table-plus filtered by non-table field?

52 views
Skip to first unread message

Donald R. Ziesig

unread,
May 10, 2011, 6:10:08 PM5/10/11
to hobo...@googlegroups.com
Hi everyone!

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.

Tiago Franco

unread,
May 10, 2011, 6:16:13 PM5/10/11
to hobo...@googlegroups.com, Donald R. Ziesig
Hi Donald,

How about: Document.all.map { |d| d.review_required? }

It's not fast, but unless you can map the review_required logic into SQL, this might be the way to go.

Thanks,
  TF

Donald R. Ziesig

unread,
May 10, 2011, 6:24:19 PM5/10/11
to hobo...@googlegroups.com
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.
--
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.

Tiago Franco

unread,
May 10, 2011, 6:34:39 PM5/10/11
to hobo...@googlegroups.com, Donald R. Ziesig
hm...

This looks ugly, but can it be done on the view like <table-plus with="&this.all.map..."> ?

TF

Matt Jones

unread,
May 10, 2011, 9:35:52 PM5/10/11
to hobo...@googlegroups.com

On May 10, 2011, at 6:24 PM, Donald R. Ziesig wrote:

> 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

Donald R. Ziesig

unread,
May 11, 2011, 9:20:10 AM5/11/11
to hobo...@googlegroups.com
Hi Matt,

Well, I thought I knew Ruby pretty well, but in the mixin example you gave below, I can't figure out what SomeObject should be.

In my case, in the Document model:

def documents_for_review
  ary =  # did this during one of my iterations at trying to make it work.

  def ary.member_class
    Document ????????

  end
  self.this = ary
end

and in the controller:

  hobo_index Document.documents_for_review

Thanks,

Don Z.

Donald R. Ziesig

unread,
May 11, 2011, 10:07:06 AM5/11/11
to hobo...@googlegroups.com
Matt,

I misunderstood your code fragment. :-[  .  The whole thing goes in the controller, in my case in the index method.  It works now.

Thanks much!

Don Z.

kevinpfromnm

unread,
Aug 8, 2011, 1:02:07 PM8/8/11
to hobo...@googlegroups.com
hey Matt, can you think of any reason it'd be throwing the same default_order error when trying to render a form?

<form with="&this.comments.new :owner => current_user" update="comments-collection" reset-form />

results:
undefined method `default_order' for #<Class:0xb543f890>

I've taken the with part and done a <%= h this.comments...inspect %> and it's returning a valid model.

...

Found a workaround but still doesn't make much sense.  It's a polymorphic comment, think it was breaking on the type/id field.

Matt Jones

unread,
Aug 8, 2011, 1:33:53 PM8/8/11
to hobo...@googlegroups.com

Can you post the complete backtrace?

--Matt Jones

kevinpfromnm

unread,
Aug 8, 2011, 2:07:08 PM8/8/11
to hobo...@googlegroups.com
https://gist.github.com/1132324

Not a whole lot in there

Matt Jones

unread,
Aug 8, 2011, 2:24:06 PM8/8/11
to hobo...@googlegroups.com

On Aug 8, 2011, at 2:07 PM, kevinpfromnm wrote:

> 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

kevinpfromnm

unread,
Aug 8, 2011, 2:44:27 PM8/8/11
to hobo...@googlegroups.com
I can get by with just specifying the fields (all one of them).  Thought I had screwed up as I didn't put in the owner reverse association but that wasn't it.  It's the polymorphic, as soon as I skip="commentable", it works
Reply all
Reply to author
Forward
0 new messages