Ruby on Rails Wednesday, October 31, 2012

On Oct 29, 2012, at 7:04 PM, arturo drlt wrote:

> Hi there i have this issue I have a view that render a partial for each
> member inside the object @foo and I have a function for infinite scroll
> so the server will be doing request after request while scrolling down
> but I don't know exactly how to make this work here is some of my code:
>
>
> def popular
> @foo = Foo.new
>
> respond_to do |format|
> response = @foo.popular
> ...
>
> flash[:notice] = "Welcome."
> format.html { render popular_foo_path}
> ....
> end
> end
> end
>
> views/foo/popular
>
> - @foo.each do |f|
> = render(:partial => "popular_foo", :locals => { :foo => f})
>
> views/foo/_popular_foo
>
> - f['thumbs'].each do |thumb|
> = image_tag(thumb['thumburl'].to_s, :alt => "thumb", :class =>
> "thumb-popular")
>
> every time you scrolldown to certain height a fuction
> $(document).infinite_scroll is called and i have it configured to make a
> new call to the method popular and I can see in the console and in the
> firebug that it do the request and succeed but it won't render the next
> results.
>

The best advice I have seen on this topic so far is to first walk, then run. Start by setting up traditional (kaminari, will_paginate) pagination. Get that working solidly. Then layer on the JavaScript to call that pagination in your page, based on the simple test: "is this marker item visible on screen or not?".

The benefit to this approach is that you silently cater to non-scripted visitors, like Google, who you ignore at your peril.

Walter

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment