Created
December 13, 2016 09:06
-
-
Save alekseyl/5dabb3d5235b0fa8d369dc36e0a58174 to your computer and use it in GitHub Desktop.
for medium article 'Rails fast collection render'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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