Rails lazy loading - ruby-on-rails

I have an app which has an index page that shows currently 10 search results. Rather than doing the standard lazy load with javascript, similar to the Railscast where new objects are shown when the user gets to the bottom of the page, I would like to have to page have a button on the bottom. When that button is clicked, I would like the next 10 objects from the search results to show and so on. Is there a tutorial for this/how would I do this?

you should use gem like
https://github.com/amatsuda/kaminari or https://github.com/mislav/will_paginate.

Related

IOS: UITableView with search: displayController not selectable?

I'm a newbie trying to create a simple sample app that takes json data from a website and list it on a UITableView.
Each voice in the UITableView is clickable to show more details.
I started from this example/app because it was clean and working:
http://nscookbook.com/2013/12/ios-programming-recipe-16-2-populating-a-uitableview-with-data-from-the-web-ios-7-and-afnetworking-2-0/
What I was missing was a searching function, so following this other page and adapting code I got it working:
http://www.appcoda.com/search-bar-tutorial-ios7/
The only problem I have is that when I search for something I get correct results filtered, but the list of results it's not clickable (to go to the details view/page) and it does not contain the small 'Rating' subtext.
Basically the filtered list only gets the 'Name' and nothing else of the original array, and the cells are not clickable.
What am I missing?
I solved eventually the issue using a SearchBar without its own display view, so basically refreshing the main tableview (already configured to show all details) if/when something is searched.
The search simply filter the main array and in all functions to display the result I show either the main array or the filtered one.
Thanks!

Calling rowToggle on Page Load using Prime Faces?

I am using primefaces 3.5, the latest release for our development work! In our homepage, we display the rows of data. When we click a row onRowSelect (SelectEvent) event we navigate to the next page with the Navigation Handler. On this landing page, I have a dataTable with expandable rows which has data in it. When I click the rowToggle icon the data is displayed in row expansion section (as it should normally).
What I need is to show the data automatically when page is loaded, with the rowToggler displaying down.
How can I achieve this?
This can be achieved using a bit of JavaScript (jQuery). All you have to do, is as your page loads call the click action of the RowExpander.
Something like this would work :
jQuery('.ui-row-toggler').click()
You can place this in your body onLoad attribute.
Source
http://forum.primefaces.org/viewtopic.php?f=3&t=8537

One page website: Rewrite URL in address-bar when clicking an anchor-link

I have set up a one-page, horizontal scrolling website with several anchors combined with DIV-id's. The website has five pages side-by-side that automatically render full-page based on the visitors browser-window.
The menu contains seven hyperlinks that address different anchors (div-id's) on the page (for example: http://www.url.com/#partsix). When they are clicked, the visitor will automatically be scrolled to the anchor part of the page. This works fine and really smooth.
The problem i'm dealing with is that, since the page is not being reloaded, the address-bar is not updated. So if a visitor wants to link to a page, or, for example, like the URL with a facebook button, it will be very difficult.
Is there a way to rewrite the address bar with the anchorlink without reloading the page?
EDIT: I have found out that i can user the action onclick="window.location.hash = hash;" on the hyperlinks. This will return the hash of the anchor it is scrolling to in the address bar. Works like a charm. But: my menu plugin does not let me add this action to the hyperlinks. So i wanted to check if i can use javascript to apply this action to all hyperlinks in the same li class. Does anyone know how?
The li class that contains all menu links is 'mc_menu mc_depth_2'

Scroll down pagination in rails using will_paginate

I wanna use infinite scroll down pagination in rails and want to pass the information like page number so that next data can be retrieved in the action and for the scroll down i can append the data to the existing data in my view.
is there any thing scroll down pagination that we can do with the will_paginate?
Thanks in advance
--Vam.
This Jquery plugin may help https://github.com/jney/jquery.pageless
to see how to do this yourself, have a look at
http://railscasts.com/episodes/174-pagination-with-ajax
to see how to use will_paginate with ajax (jquery). Ryan shows how to modify the usual will_paginate approach. First how to modify the links of the pagination bar and then he shows how to modify the view to display newly loaded objects... In this video he replaces shown items by newly loaded items. You'd just have to tweak the index.js.erb to append them.
nevertheless ... you might also want to checkout his video
http://railscasts.com/episodes/114-endless-page
in which he shows what you asked for but without will_pagination

Ajax pagination like Twitter

Is there any plugin/gem or an easy way for accomplish a pagination functionality like Twitter?
This means, showing a "More" button that shows more posts (for example) below once it's clicked, using Ajax.
If there's any easy way for modifying something from will_paginate plugin, that would be useful too.
I use this for easy pageless pagination. Seems to be a better solution w/o the more button.
http://github.com/jney/jquery.pageless
I've added a Twitter-like 'more' button on the app I'm currently working on. I used the exact method from http://railscasts.com/episodes/114-endless-page.
In this solution, more results are added to the bottom of the div once you scroll down to the bottom of the page resulting in an endless page. I changed the javascript so that it would send off the ajax request to add more results to the bottom of the div only when the 'load more' button is clicked.
The will_paginate project wiki has an entry on Ajax pagination. It's really quite straightforward.
I use Twitter-like pagination in one of my apps, so I'll just point you to that:
http://github.com/tsigo/jugglf/blob/master/lib/twitter_pagination.rb - Hooks into will_paginate to display the "More" button
http://github.com/tsigo/jugglf/blob/master/app/views/members/raids/index.html.haml - The view using the renderer from above
http://github.com/tsigo/jugglf/blob/master/app/views/members/raids/index.js.erb - The RJS view that appends the next set to the page

Resources