Rails cache_digests and conventions

When we cache partial on rails using caching digests, how is conditional logic handled in partial processing? Does it cache the complete template and then apply the conventions so that the right json / html can be accessed by the correct user?

+3
source share
1 answer

It caches the complete template and then applies the conventions so that the right json / html can be served to the right user?

This part of the question seems a little unclear to me, so I will provide various options based on what “conventions” may be.

, , @variables ( -). :

# users.haml
.welcome_block
  - if @user.admin?
    %h4 Hello, admin!
  - else
    %h4 Hello, user!

, cache ['users_haml'], ( - ). , , h4, , . , digest users_haml, cache, - .

, cache @user . , users.haml, , / . , digest User, cache_digests N N .

, , - , , :

# users.haml
- cache [@user.month_of_birth]
  - if @user.month_of_birth == 'October'
    = render 'partial_one'
  - else
    = render 'partial_two'

, . , partial_one? cache_digests , , ( )?

, . , , , users.haml partial_one, partial_two, users.haml, .

+1

All Articles