Module ConditionalFragmentCaching::ActionView
In: lib/fragment_caching.rb

Methods

Public Class methods

[Source]

    # File lib/fragment_caching.rb, line 35
35:     def self.included(mod)
36:       mod.class_eval do
37:         # This method acts in much the same way as
38:         # ActionView::Helpers::CacheHelper.cache - but with the first parameter
39:         # acting as a flag to whether it should cache the fragment.
40:         #
41:         # === Examples
42:         #
43:         #   <% conditional_cache @current_user.nil? do %>
44:         #     <!-- view code that will only be cached when @current_user is nil -->
45:         #   <% end %>
46:         #
47:         # Just like the default cache method, it also accepts additional
48:         # parameters:
49:         #
50:         #   <% conditional_cache @current_user.nil?, :page => params[:page] %>
51:         #     <!-- view code -->
52:         #   <% end %>
53:         def conditional_cache(conditional, name = {}, &block)
54:           conditional ? @controller.cache_erb_fragment(block, name) : block.call
55:         end
56:       end
57:     end

Public Instance methods

This method acts in much the same way as ActionView::Helpers::CacheHelper.cache - but with the first parameter acting as a flag to whether it should cache the fragment.

Examples

  <% conditional_cache @current_user.nil? do %>
    <!-- view code that will only be cached when @current_user is nil -->
  <% end %>

Just like the default cache method, it also accepts additional parameters:

  <% conditional_cache @current_user.nil?, :page => params[:page] %>
    <!-- view code -->
  <% end %>

[Source]

    # File lib/fragment_caching.rb, line 53
53:         def conditional_cache(conditional, name = {}, &block)
54:           conditional ? @controller.cache_erb_fragment(block, name) : block.call
55:         end

[Validate]