title: Rails: Using Ajax
body: <p>Problem: <strong>Trying to implement "like" function on my blog</strong></p>
  
  <p><strong>PostIndex:</strong></p>
  
  <pre><code>&lt;% @posts.each do |post| %&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;%= post.name %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= link_to post.content, post %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= post.created_at.strftime("%Y/%m/%d, %I:%M%p") %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= post.view %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= post.like %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= post.hate %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= link_to 'like', like_post_path(post), :remote =&gt; true %&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>PostController:</strong></p>
  
  <pre><code>def like
   @post = Post.find(params[:id])
   @post.like += 1
   @post.save
  
   respond_to do |format|
      format.js
   end
  end
  </code></pre>
  
  <p><strong>app/views/posts/like.js.erb</strong></p>
  
  <pre><code>$('#post').html("&lt;%=j @post.like %&gt;");
  </code></pre>
  
  <p><strong>Question:</strong>
  <br>
  I believe I'm not correctly pointing at the post I'm looking at in like.js.erb.
  <br>
  In the index file, Simply doing &lt;%= @post.view  %> worked. But how do you do it in like.js.erb?</p>