Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails how to cache partial?

I'm using a render partial: 'fragment', locals:{obj:item} for every row in table. It takes long time to process the whole page.

Is there a way to save all fragments for each item at first loading and don't render them again each time during the server works?

UPDATED

card/index.html.haml
%table 
  =render partial: 'card/card', collection: @cards, cached: true

card/_card.html.haml
-cache card do
  %tr=card.title

card_controller.rb
def index
  @cards = Card.order(:name)
end

SOLVED

Cached started to work after I add to development.rb:

config.action_controller.perform_caching = true
config.cache_store = :memory_store, { size: 64.megabytes }
like image 747
user2572790 Avatar asked Dec 30 '25 03:12

user2572790


1 Answers

Or you can run rails dev:cache to toggle caching.

like image 105
Олег Бабенко Avatar answered Jan 01 '26 23:01

Олег Бабенко



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!