Why is my area cached?

I have a scope that looks like this:

scope :top, order('score DESC') 

In my controller, it is used as follows:

 def top @users = User.top render "list" end 

Now it seems that this area is cached for no reason. If I load the top page, add the user and reload it, the user will not appear in the list.

If I do this:

 def top @users = User.order('score DESC') render "list" end 

Results are not cached. What's going on here? I am using Ruby 2.0.0 and Rails 4.0.0

+4
source share
2 answers

Found what the problem is! The scope should be defined as follows:

 scope :top, order: 'score DESC' 
+1
source

I think if you use lambda then it should not be cached:

scope :top, lambda { order('score DESC') }

But then again, I am not familiar with the new caching of Rails 4 areas.

+6
source

Source: https://habr.com/ru/post/1495223/


All Articles