I'm looking for a tutorial or a piece of code that can leads me to create a page
where we can find only 10 data rows per page and navigating with Ajax previous/next arrows
and also page number (i.e.: < 1 2 3 ... 10 > ).
Thank you very much.
A good place to start is Mislav's will-paginate plugin. The Readme at that link should explain how to use it.
Edited:
There's also a screencast on RailsCasts about Ajax pagination. I haven't watched it, but his stuff is usually really high-quality and easy to follow.
it's not ajax but maybe it's useful for you... when you use haml and haml_scaffolding in rails it's authomatic the pagination using this kind of sacffolding
Related
I've finally decided to give angularjs a whirl and i'm running into some early trouble.
I'm using Rails 3.2 and the Slim template gem for the view.
I'm just trying the example from the angularjs site here: http://angularjs.org/#todo-html
Here's the relevant bit:
<div ng-controller="TodoCtrl">
<span>{{remaining()}} of {{todos.length}} remaining</span>
Which in slim would be something like:
div(ng-controller="TodoCtrl")
span {{remaining()}} of {{todos.length}} remaining
The problem is Slim just prints:
{{remaining()}} of {{todos.length}} remaining
literally as a string.
Anyone able to get Slim and Angular to play together?
I finally got it to work.
I had to go into my layout and do this:
html(ng-app='')
You can probably add that to a div on the particular page also.
div(ng-app='')
div(ng-controller="TodoCtrl")
span {{remaining()}} of {{todos.length}} remaining
Hopefully this helps someone. It took me a bit to figure out.
You can also do it like so:
html [ng-app]
Or:
div [ng-app]
div [ng-controller="TodoCtrl"]
span {{remaining()}} of {{todos.length}} remaining
Can someone show me or know of a good example that shows how to display data in say a 4 x 3 grid with a pager in Ruby on Rails. The examples I'm finding all display the data in a top down manner. I'm looking for something more like a product grid that I can page through.
Have a look at the pagination railscasts, they are really helpful:
http://railscasts.com/episodes?utf8=%E2%9C%93&search=paginate
I am using Kaminari to paginate some results from a db query.
I would like to apply specific styling to the first page of the results.
The operation is very easy once I know on what page the user is, but I can't find a way to detect the current page.
If you want to check for first page you can do it like this:
if object.first_page?
#your logic here
end
If you find the specific page you can do something like this:
current_page_no = object.current_page
For more info refer: http://www.rubydoc.info/github/amatsuda/kaminari/master/Kaminari/PageScopeMethods
Have you generated the partials that kaminari uses?
See the section titled "Customizing the pagination helper" here:
https://github.com/amatsuda/kaminari
Oncey ou do that, you can edit the _paginator.html.erb file (or other kaminari partials if you need to) in order to get the pagination functionality you're looking for. These partials allow you to use local variables, like "current_page", "num_pages" and a few more. Sounds like that's what you're looking for.
Here's what those partials look like, if you want to see them before running the generator:
https://github.com/amatsuda/kaminari/tree/master/app/views/kaminari
Hope that points you in the right direction.
2020 Update. As of now I am able to do #users.current_page.
on mysite I have the ability to add comments. Sometimes users enter comments will links (href. ...)
I would like to have those links to be clickable/linkable (a href) when the comment is displayed to users.
how with Rails 3 can I take a comment, and look for links and then wrap those links in an a href tag that opens in a new window?
Thanks
The simplest way is to use the auto_link method built into rails.
Note: In Rails 3.1 auto_link has been moved into a separate gem.
idlefinger's suggestion of #auto_link is perfect. I know it's not the question you originally posed, but wanted to suggest: also check out #simple_format, which will nicely format your users' use of newlines into br and p tags.
I am following the NerdDinner MVC application as a guide to do my paging. What if my results are more than 1000 pages, I want to show perhaps the numbers 1 2 3 4 5 .. 10 on the bottom of my page and perhaps something like >> to move to the next set of 10 or 100 pages.
How can I do this in MVC?
I use the implementation demonstrated by Martijn Boland at: http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/
Go for JQuery Datatables. that's the easiest way to solve pagination issues.Return the controller as JsonActionResult and supply it to datatables data.
The remaning will be taken care by data tables. like pagination, search functionality at all.
Check this https://datatables.net/examples/