Method: ActionView::Helpers::CacheHelper#cache_if
- Defined in:
- actionview/lib/action_view/helpers/cache_helper.rb
#cache_if(condition, name = {}, options = {}, &block) ⇒ Object
Cache fragments of a view if condition is true
<% cache_if admin?, project do %>
<b>All the topics on this project</b>
<%= render project.topics %>
<% end %>
223 224 225 226 227 228 229 230 231 |
# File 'actionview/lib/action_view/helpers/cache_helper.rb', line 223 def cache_if(condition, name = {}, = {}, &block) if condition cache(name, , &block) else yield end nil end |