Skip to content

Instantly share code, notes, and snippets.

@alekseyl
Created December 13, 2016 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alekseyl/5dabb3d5235b0fa8d369dc36e0a58174 to your computer and use it in GitHub Desktop.
Save alekseyl/5dabb3d5235b0fa8d369dc36e0a58174 to your computer and use it in GitHub Desktop.
for medium article 'Rails fast collection render'
class Product <ActiveRecord::Base
after_commit :prerender
def prerender
keys = [ [:user, :admin, :moderator, nil], [:ru, :en ] ]
keys.pop.product(*keys).each do |lr|
# lr - locale + role
ApplicationController.render(
assigns: {locals: {product: self, role: lr[1], locale: lr[0]} },
inline: '<% render partial: "products/product", locals: @locals %>')
#of course products/_product.html.slim must start with
#-cache[product, ...] do
end #each
end #prerender
end #Product
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment