Active Pagination and Active Search

I know it’s simple but why does the rails scaffold not include pagination and some basic sql search like ransack? Ransack and Kaminari are usually the first thing I have to add to every view unless I plan to go fancy.

Even deeper, why don’t we have active_pagination and active_search (excluding non sql search here) yet? I mean, we even have actiontext! This would also provide a clear standard for our JS Frameworks to interact with rails api’s (looking at jbuilder with JSON:API).

Looking at the ruby toolbox, the differences in downloads are not that massive:

1 Like

I remember when I started using rails (1.x), it used to have pagination builtin. I don’t remember why it was removed, but I think it was mostly because it was really slow. I guess we’re going full circle now.

ransack is more advanced than kaminari…

Maybe add Pagy gem?

But rails new can always provide some default gems… Advanced devs can cleanup and adjust generators to their own set of gems Maybe idea of interactive generator would be great fit for that (from different thread in mat wtfs)

2 Likes

I remember that too! The reason it was removed was because it loaded all of the records in memory and did the paging in memory.

I’m not sure why it wasn’t changed to use SQL instead of being totally removed though :man_shrugging:

Ransack is a very powerful gem, but its form API has always felt a little odd to me. It’s essentially its own query language, but you write it inside the view. In its current form, I’m not sure that it would fit as a default gem. I do agree it would be nice to have some additional out-of-the-box help, though.

I have experimented with creating an alternative that uses Rails’ stock form builder and Active Record directly. I welcome feedback on its design and how it could be more “Railsy”:

https://github.com/jonathanhefner/talent_scout

1 Like

Great discussion here, I’ve created a github issue to discuss ideas on how to bring this into rails: Active Pagination and Active Search - #4 by paulcsmith.

@jonathanhefner thank you for the great open-source contribution. I think you have a lot of great ideas in your project. I’d love to find a way to combine forces and tackle the problem together. I agree with you about ransack API being weird.

I’ve built an implementation for my work on top of ransack, but try to abstract it away so it can later be replaced by another API. The brilliance of ransack is the predicates and how easy it is to add them. The downfall is a flat key structure and weird custom ransacker API I always have to lookup to figure out how to use.

For the URL structure, I opted to more of Elastic Enterprise Search style you can find here: Search UI - Pre-built Search Experiences & Front-end Components | Elastic.

My first step on the latest iteration was infact to define a clear data-structure that can support all these configurations. I wanted it to be simple enough to be transformed into JSON and serve as a starting point for offline/client-side search as well.

1 Like

Opps, accidentally used the wrong link. Github issue: [proposal] ActiveSearch - Rails Search · Issue #40989 · rails/rails · GitHub and discussion on feature request here: [Feature Proposal] ActiveSearch - Rails Search

Hii jonathanhefner, I am facing the same problem and now got the solution from your post. Thanks for sharing this. Please keep suggesting such post.

KrogerFeed