I was frustrated to learn that fresh_when() doesn't support
Enumerable. Since I would think that the bulk of the ETag savings
would be on large index actions, rather than individual show actions,
I wrote a quick-and-dirty helper for application_controller.rb that I
thought others might find helpful, too.

  # Handle conditional rendering for a single collection. Depends on
  # unique IDs, so will not work with data from more than one model at
a
  # time.
  def fresh_collection? collection
    id_array = []
    collection.each { |c| id_array << c.id }
    id_array.sort!
    fresh_when etag: id_array, public: true
  end

There's probably a better way to do this, especially if you have an
index action that's pulling data from multiple models, but this was
enough to scratch my immediate itch. Does anyone know of a better
solution?

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to