ruby on rails
I'm using acts-as-taggable-on gem v.2.4.1 with rails v.3.2.13 and ruby 1.9.3p392. I've just upgraded the gem from v.2.2.1 to v.2.4.1 and following these instructions I've added a 'cached_tag_list' column to my database. The column seems to update as expected when a record is saved/updated but when I try to fetch tagged records I can still see SQL tag queries being performed (and not fetching cached tags). This is my code in my view:
<% if !tape.tag_list.empty? %>
<% for tag in tape.tags %>
<span><%= tag.name %></span>
<% end %>
<% end %>
My model has the following line:
acts_as_taggable_on :tags
And here's a screenshot from newrelic showing the SQL queries being performed even though these records have saved tag strings in the ''cached_tag_list' database column.
Any ideas how to enable caching with this gem?
Thanks, Alex
Until this bug is fixed, here's a workaround I've implemented:
<% if tape.cached_tag_list != "" %>
<% for tag in tape.cached_tag_list.split(', ') %>
<span><%= tag %></span>
<% end %>
<% end %>
Since the cached_tag_list column is updated properly every time a record is saved I'm using it to get each record's tags without calling extra SQL queries, just one. Since the cached_tag_list column stores a string with comma-seperated tags I'm using split() function to get each one of them.
I'm sharing this in case this is useful to anyone else..
链接地址: http://www.djcxy.com/p/36024.html上一篇: 索引方法从关联的ActiveRecord对象导出ElasticSearch
下一篇: 红宝石在轨道上