I am trying to paginate objects from a has_many/:through relationship
using Paginator.
current_user.things returns the objects that I’d like to paginate. For
testing, I tried to make it 1 item per page. I initialise the paginator
as follows:
I don’t know how to obtain @things now though, I don’t want to be using
Things.find_all (as the wiki example shows) as I know which things I
want to be paginating (current_user.things). How can I make an array of @things that contains the right items (e.g. starts and ends at the
correct offset)?
@things = current_user.things will obviously just return all things,
which isn’t correct. Somehow I need to select only the correct portion
of this?
Unfortunately I can’t do this, as I’m using a has_many/:through
relationship so am not using a find() call. There is no “user_id”
column, that’s handled by a permissions table.
This looks promising, but I can’t get it to work. As I already have
current_user.things, I can’t query using the class find*() methods (for
the same reason as above). I also can’t find any methods for the
array/collection that allow an offset and limit to be passed to them.
Since posting I’ve actually found this link: BigBold - Informasi Tentang Bisnis dan Marketing, which solves the problem
in pretty much the same way as Typo (and therefore the code I borrowed).
In this instance, I think I’ll have to make do with a few lines extra
Cheers.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.