On Wed, May 23, 2012 at 1:59 PM, jhstephenson <[email protected]> wrote:
> A couple of questions about pagination:
>
> 1. I have a view where I display Customer Information and then underneath it
> display the products they have purchased in a Table-Plus.
>
> The display works fine except that I do not get any pagination. All records
> are displayed for a customer. This isn't a big deal for customers with only
> a few records, but when I have some over 100 (I actually have some over
> 1000) it really doesn't work.
>
> I have the following in my Products Controller:
>
> class ProductsController < ApplicationController
>
>   hobo_model_controller
>
>   auto_actions :all
>
>   def index
>       hobo_index Product.apply_scopes(:search => [params[:search],:name,
> :date_ordered, :date_received],
>       :joins=> :customer, :order_by => parse_sort_param(:date_invoiced,
> :name, :customer, :vendor),
>       :paginate => true, :per_page => 20)
>   end
>
> end
>
> Any ideas?

What version of Hobo are you using?

I usually call the functions directly rather than using apply_scopes:
 .paginate(params[:page]).     apply_scopes just calls the functions
supplied as arguments, so maybe if you replace it with :paginate =>
params[:page] it will work better.

>
> 2. On a view for a list of customers by themselves pagination works fine,
> except that at the bottom of the screen I get this:
>
> « Prev 1 2 3 4 5 … 11 12 Next »
> « Prev 1 2 3 4 5 … 11 12 Next »
>
> The pagination links are repeated twice.
>
> Any ideas on that one?

Can you post your DRYML?   You're probably using a tag (such as
table-plus) that includes pagination, and then adding your own
page-nav somehow...

>
> 3. While this isn't strictly related to pagination it is about the
> controller pasted above....
>
> I would like the resulting table-plus view to be sorted in date_invoiced
> (descending) order. When I try to replace:
>
> parse_sort_param(:date_invoiced, :name, :customer, :vendor),
>
> with
>
> parse_sort_param(:date_invoiced DESC, :name, :customer, :vendor),
>
> I get errors.
>
> Is there a different way to do that?
>

The parse_sort_param is so that the user can choose the sort order by
clicking on headers.   If you want to choose it explicitly, just use
:order_by => "date_invoiced DESC" or .order_by("date_invoiced DESC").

If you're just looking to set the default, one way of doing it is to
set the param if it's not already set, so that parse_sort_param thinks
the user did it:

params[:sort] ||= "-date_invoiced"   (remove the dash to sort in the
other direction)

Another, probably better mechanism is to use default_scope in your
model to set the default sort order.

default_scope :order => "date_invoiced DESC"

Bryan

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to