Leave a Comment

Comment Preview:

Comments

  1. Avatar

    brian
    Posted: 2 April, 2007

    Great post!!! This was exactly what I was looking for. Thank you!

    Reply to this comment.
  2. Avatar

    Duncan Gough
    Posted: 30 April, 2007

    Wouldn’t it be better to offload that work to the database, though?

    Reply to this comment.
  3. Avatar

    juco
    Posted: 8 July, 2007

    How exactly would you sort the posts inside the sorted weeks? I am doing something similar in my app but can’t figure out how to sort the records inside the group.

    Reply to this comment.
  4. Avatar

    Ariejan
    Posted: 8 July, 2007

    @juco: You could do it like this:

    render :partial => ‘post’, :collection => @posts.sort {|a,b| a.title < => b.title}

    See Ruby’s sort documentation on how to sort your @posts.

    Reply to this comment.
  5. Avatar

    skwasha
    Posted: 10 October, 2007

    So, I can get the groups listed separately… Now let’s say I want to re-render only one of the partials (say by column header sorting on a diff property). Is this possible? How would you go about it?

    Reply to this comment.
  6. Avatar

    Ariejan de Vroom
    Posted: 11 October, 2007

    Author Comment

    @skwasha: You could give every week a seperate id: instead of <div id=”week”>, you’d use <div id=”week-<%= week %>”>

    When you want to update your group, just select the appropriate data from you database (using conditions on your model like find_all_for_week or something. And then, using RJS, replace the div:

    render :update do |page|
    page.replace_html “week-#{week}”, :partial => ‘your group partial’
    end

    Reply to this comment.