Stupid Newbie Tricks ... Adventures in Hobo-space

7 views
Skip to first unread message

MichelV69

unread,
Aug 23, 2009, 5:29:19 PM8/23/09
to Hobo Users
I'm working on my first serious Hobo project. I need to completely
change the behavior of the "index" for one of my views. Easy enough,
I would think.

I have added an "index" method to the controller with the extra bits I
need. I can see by MySQL logs that all queries I expect to fire are
firing.

In my application.dryml, I've added the appropriate "extend tag='index-
page'" with a simple draft of the mechanism I need.

Mongrel returns no errors, but instead of seeing my content I get "The
page you were looking for could not be found".

If I introduce an error into the index-page code in application.dryml
and refresh my browser, Mongrel spits up debugging as I would expect.
So, I know that is -is- in fact processing that tag and my routing is
correct.

Does anyone have any ideas about what I might be doing wrong here?

Ritchie Young

unread,
Aug 23, 2009, 9:12:10 PM8/23/09
to hobo...@googlegroups.com
The standard way of doing it is to create a page called index.dryml under view directory for the particular controller.

You can completely redo the page in that file or you can call <index-page></index-page> and within that tag, pass parameters to override appropriate sections of the page (see the one generated in pages.dryml). Eg:

<index-page>
  <content-body:>
    Lots of clever stuff
  </content-body:>
</index-page>

I think what you may be doing is extending the base version of the index-page tag which is polymorphic so I'm not sure what should happen.

Regards
Ritchie
--
Ritchie Young

Email: rit...@cafebop.com
Mobile: 0412 210415
Skype: ritchiey71

Bryan Larsen

unread,
Aug 23, 2009, 9:22:17 PM8/23/09
to hobo...@googlegroups.com
Yes, I recommend following Ritchie's method. That is the standard way
of doing it.

However, your method will work if you do it like so:

<def tag="index-page" for="ModelName">
...
</def>

Bryan
> Email: rit...@cafebop.com <mailto:rit...@cafebop.com>

MichelV69

unread,
Aug 24, 2009, 9:18:00 AM8/24/09
to Hobo Users
Good morning, guys! Thanks for all your suggestions. I went ahead
with using "index.dryml", and got the same effect.

I've put the relevant code slices at http://gist.github.com/173855 ...
I'd really appreciate someone with more experience taking a peak and
telling me what I've done wrong.

Ritchie Young

unread,
Aug 24, 2009, 10:06:17 AM8/24/09
to hobo...@googlegroups.com
Application.dryml is misspelt:

> app/views/taglibs/appliction.dryml


I can't see anything else wrong.

--
Ritchie Young

Email: rit...@cafebop.com

MichelV69

unread,
Aug 24, 2009, 11:18:10 AM8/24/09
to Hobo Users
On Aug 24, 10:06 am, Ritchie Young <ritch...@gmail.com> wrote:
> Application.dryml is misspelt:
>
> > app/views/taglibs/appliction.dryml
>
> I can't see anything else wrong.
>
... that was a pre-coffee typo. :) The actual file on the drive has
the right name. Thank-you.

What is interesting is that if I remove the "index" definition from
cdrs_controller.rb, then I no longer get the rather enigmatic "The
page you were looking for could not be found" error. Even if all have
is the "@cdr = find_instance" line, I get the error. I'm baffled.

Matt Jones

unread,
Aug 24, 2009, 11:31:38 AM8/24/09
to hobo...@googlegroups.com
Why are you calling find_instance? You don't appear to use the result,
and it's not going to work for an index action anyways (it essentially
calls Cdr.find(params[:id]) in this case, which will clearly fail).

The "page not found" is the result of Rails catching the
RecordNotFound exception and displaying a 404 error page.

--Matt Jones

MichelV69

unread,
Aug 24, 2009, 11:40:34 AM8/24/09
to Hobo Users
On Aug 24, 11:31 am, Matt Jones <al2o...@gmail.com> wrote:
> Why are you calling find_instance? You don't appear to use the result,  
> and it's not going to work for an index action anyways (it essentially  
> calls Cdr.find(params[:id]) in this case, which will clearly fail).
>
> The "page not found" is the result of Rails catching the  
> RecordNotFound exception and displaying a 404 error page.
>
> --Matt Jones
>
Hi, Matt. I'm doing it, because I inferred from the Agility
tutorial that I had to. If I don't do that, I just get a blank page;
nothing renders at all. Not even the menus.

Thank-you for explaining what the error means. Can you point me in
the right direction of what I -should- be doing to replace the index
page for a given MVC trio? I'm sure I won't be the only new comer
trying to do this as part of a project.

Matt Jones

unread,
Aug 24, 2009, 11:59:08 AM8/24/09
to hobo...@googlegroups.com

The issue you had with the blank pages comes from the polymorphic
default page tags - if there's no object(s) in 'this', Hobo renders
the default (which is empty).

I'd recommend you do this in the controller:

def index
@first_day_billing = Time.now.at_beginning_of_month
@last_day_billing = Time.now
@cdrs = Cdr.find(:all, :conditions => ['date >= ? AND date <= ?',
@first_day_billing, @last_day_billing], :order => 'unique_stamp')
end

(pulling the find call into the model - say a method this_month_so_far
- is up to you. If 'date' had a more descriptive name like billed_on,
you could also use Hobo's automatic scopes to say things like
Cdr.billed_before(Time.now), etc)

Note that the DRYML view code will automatically pick up the instance
variable with the pluralized model name and put it into 'this', so the
view can be the same. I'd also suggest that, unless the code in
invoice-page is going to be reused, it's probably better to just do it
inline. It avoids the problem that plain Rails sometimes gets into,
where a page is shattered into a million little partials.

--Matt Jones

Brett Nelson

unread,
Aug 24, 2009, 12:03:42 PM8/24/09
to Hobo Users
Excuse me for jumping in here, I just did this the other day so it is
still fresh...

The way I like to make changes like this is doing it in small steps.

Start with a working Hobo default model controller setup, nothing
custom yet.

Redefine the index page with index.dryml something like "Hello World"
for starters, refreshing the browser for that web page would then show
a white blank screens that says "Hello World"

Then replace that with "<index-page></index-page>" in index.dryml,
refresh the page and should be back to the default hobo index page.

Now lets try and do something with the controller code at this point
index should not be defined in the controller so lets define one:

def index
@cdrs = nil # notice it is @cdrs plural
end

The nil should break it so refreshing the page will be white nothing.
Then change it to this:

def index
@cdrs = find_or_paginate(Cdr, {})
end

That should get a page back looking like the default hobo page.

At this point start customizing in the dyml with

<heading: replace>
My new heading here
</heading:>

And refresh the browser to see if that takes.

You could then start adding your own @myvars in the controller code
and referencing them in the index.dryml to create the custom index
page you want.

I've found that it is much easier and less frustrating to take it just
one little step at a time always checking to see if things are still
working,

Hope that helps.

Brett

Brett Nelson

unread,
Aug 24, 2009, 12:19:07 PM8/24/09
to Hobo Users
If I do an @models = Model.find(:all) in the controller I get:

undefined method `total_pages' for #<Array:0x8c752ec>

In the page refresh so I was using the find_or_paginate method
instead. Am doing this with latest git hobo.

Brett

MichelV69

unread,
Aug 24, 2009, 1:32:55 PM8/24/09
to Hobo Users

Matt & Brett,

Thanks very much for your patient and thorough explanations. I'm
back on track with things behaving as I expect now.

I'm finding the biggest challenge to Hobo right now is, given how
well it does so much, is just figuring out how to do "special case"
changes like this.

Thanks again for answering my questions. Its very much appreciated.

Matt Jones

unread,
Aug 24, 2009, 3:05:16 PM8/24/09
to hobo...@googlegroups.com
There's an issue with the default index-page tag; it automatically
includes pagination nav, which breaks if you feed it a plain Array.

For a quick fix, add:

<top-page-nav: replace />
<bottom-page-nav: replace />

In your index.dryml page if you're using an array rather than a scope.

--Matt Jones

Tom Locke

unread,
Aug 24, 2009, 3:14:11 PM8/24/09
to hobo...@googlegroups.com
> There's an issue with the default index-page tag; it automatically
> includes pagination nav, which breaks if you feed it a plain Array.
>
> For a quick fix, add:
>
> <top-page-nav: replace />
> <bottom-page-nav: replace />

There's also the sorthand <index-page without-top-page-nav without-
bottom-page-nav/>

Or just call Model.paginate, instead of Model.find

Tom

MichelV69

unread,
Aug 24, 2009, 4:52:27 PM8/24/09
to Hobo Users
What is the easiest way to use "table-plus" with a custom
collection?
My application has to deliver "per day" summary billing of an
arbitrary number of days, for a set of resources. The array I'm
building contains "date, pbx, did, customer, this_month_mins,
last_month_mins" in each hash/ record.

I don't want to print the individual data records; there can be
hundreds totaled in "this_month_mins". So I am doing some behind-the-
curtain accumulations, and using that to build the per-day hash
summary record. I then want to use the very spiffy looking "table-
plus" to put it out on the screen.

I'm having some troubles inferring from the docs I have if/how to do
this. Thanks very much in advance; Hobo is very cool, and I'm
enjoying working with it.

kevinpfromnm

unread,
Aug 24, 2009, 5:14:25 PM8/24/09
to Hobo Users
With table plus you can specify what fields you want to display. For
things that aren't part of the record you can do a couple different
things:

1. if it's related to the record you can make a method in the model to
return what you're after - like your sum
2. you can also do association methods like association.count,
association.sum, etc.
3. you can override the view tag for the particular column and do
whatever you need

As a last note, if you put in a field that is not directly part of
your main record's database table, you'll have to do some tweaks to
get sorting/searching/filtering working.

Bryan Larsen

unread,
Aug 24, 2009, 5:18:56 PM8/24/09
to hobo...@googlegroups.com
Support for this was patched in at the end of April. There's even a
test for it, which you can use as your example:

http://github.com/tablatom/agility/commit/57400608ae1ae27fec18b4f22ef63ccfb11c3b31

Bryan

Brett Nelson

unread,
Aug 24, 2009, 5:49:43 PM8/24/09
to Hobo Users
Matt & Tom thanks on the pagination help!

Ended up with something looking like this:

@things = Thing.paginate(:page => params[:page],:per_page => 15)

Brett


On Aug 24, 2:18 pm, Bryan Larsen <bryan.lar...@gmail.com> wrote:
> Support for this was patched in at the end of April.  There's even a
> test for it, which you can use as your example:
>
> http://github.com/tablatom/agility/commit/57400608ae1ae27fec18b4f22ef...

MichelV69

unread,
Aug 24, 2009, 9:45:41 PM8/24/09
to Hobo Users
On Aug 24, 5:18 pm, Bryan Larsen <bryan.lar...@gmail.com> wrote:
> Support for this was patched in at the end of April.  There's even a
> test for it, which you can use as your example:
>
> http://github.com/tablatom/agility/commit/57400608ae1ae27fec18b4f22ef...
>
> Bryan
>

Thanks, Bryan. Unfortunately, this seems to choke on the data
structure I am using seems to choke it, if I follow the example code.
Here's a typical record in the collection:

[{"date"=>"2009-08-01", "report_day"=>[{"last_month_mins"=>-9,
"this_month_mins"=>10, "customer"=>"First Customer",
"did"=>"123-456-7890", "pbx"=>"DEMO-01"}]

... I expect I'll have to hand-code something less cool looking.
Reply all
Reply to author
Forward
0 new messages