Petercopter
Petercopter

Reputation: 1258

Bypass cache check for logged in users in Ruby on Rails?

I am using cache_action in my controllers, and I would like to bypass checking the cache for logged in users on some pages. My login system is Devise/Omniauth.

I thought I would find something in the caching system that I could integrate into a before_filter, but no dice.

How would I go about accomplishing this?

Upvotes: 1

Views: 237

Answers (2)

cweston
cweston

Reputation: 11637

Since Rails 4, you can use the CacheHelper's cache_unless and Devise's user_signed_in?

<%= cache_unless user_signed_in?, project do %>
  <b>All the topics on this project</b>
  <%= render project.topics %>
<% end %>

Upvotes: 0

Zach Kemp
Zach Kemp

Reputation: 11904

I believe you can do something like this, but I've never tried it myself:

caches_action :index, :unless => lambda { user_signed_in? }

Upvotes: 2

Related Questions