Ruby on Rails Wednesday, October 31, 2012

From the question you have posed, and the information you have provided, there is not a simple 'do this' answer.  You need to get a bit further down the path of what you want to achieve.  (unless someone knows some magic foo that I am unaware of).

Looking at what you have so far, it would seem that you have the basic functionality of the page, and you have an idea of what you want to achieve, but you do not yet appear to have a strategy or plan for how you are going to achieve it.  I have never implemented continuous scroll, but giving it some cursory thought, I would begin by asking myself some questions.

1.  How is the page update going to take place when I extend the contents.  
     eg.  - replace the whole page each time the list updates
            or -  replace the list section 
            or - add additional items at the end
     Do I let the page size continue to grow indefinitely or do I remove some items from the other end.

2.  If I am going to manage addition/deletion of items.  The items will probably be best structured in an an html list or table, and each may need a unique id, or can I just append/prepend  to the list of items.

3. What mechanism will I use to identify the next 'page' of items I want to add to the list.

4.  How is my controller going to get the correct list of items to add? ie what paging mechanism am I using.

5.  How am I going to handle the ajax response that contains the items.  I am going to need some js code to append/prepend or insert the items into the list.  

6.  What form will my response be in.  I can send some javascript using an erb template to insert the items, or I could have a js function on the browser side ready to handle the response (eg as a success callback handler.)  Or I could return data as json and handle the paging more fully in the browser js.

7.  Finally having thought about all this, I would do some googling to see if someone has already implemented such a thing in a form I could learn from, or is there maybe a js library that might already provide most of the functionality I require.  

I am sorry this is not a direct answer, but hopefully it may help to clarify what you are trying to achieve and how you are going to go about it.


Tonypm
 


On Monday, 29 October 2012 23:05:43 UTC, Ruby-Forum.com User 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.

--
Posted via http://www.ruby-forum.com/.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DNjP5tChIy4J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment