Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fragment cache "like" buttons ? (Rails 3.2, memcached)
    primarykey
    data
    text
    <p>My Rails app has <code>Post</code> and <code>Member</code> models. Within <code>posts/:id/show</code> contains a "like" button which Members can click, or "Unlike" if <code>@member</code> has already "liked" this <code>@post</code> already. </p> <p>(This button will link to a post action that does some ajax and makes the "like" button change into a "unlike" button)</p> <p>Whats the best practice for caching the button? (below code obviously doesn't cache the button html). </p> <p>Should I add <code>:touch =&gt; true</code> to <code>member.rb</code>, and then make a cache key for the button e.g. <code>&lt;% cache ['V1', @post, @member, 'like_button']</code> ? (seems redundant?)</p> <p><strong>post.rb</strong></p> <pre><code>has_many :likes </code></pre> <p><strong>like.rb</strong></p> <pre><code>belongs_to :member belongs_to :post </code></pre> <p><strong>member.rb</strong></p> <pre><code>has_many :likes </code></pre> <p>*<em>posts/show.html.erb *</em></p> <pre><code>&lt;% cache ['V1', @post, 'show'] do %&gt; &lt;h1&gt;@post.title&lt;/h1&gt; &lt;div class="content"&gt;@post.content&lt;/div&gt; &lt;% end %&gt; &lt;%= render 'like_button', :post=&gt; @post, :member =&gt; @member %&gt; </code></pre> <p>** posts/_like_button.html.erb **</p> <pre><code>&lt;% if member.liked_post?(post) %&gt; &lt;%= link_to unlike_post_path(post), :method =&gt; :post, :remote =&gt; true, :class =&gt; 'btn' %&gt; &lt;% else %&gt; &lt;%= link_to like_post_path(post), :method =&gt; :post, :remote =&gt; true, :class =&gt; 'btn' %&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload