Problem: Ajax is not behaving as it should be.
PostIndex:
<tr>
<td><%= post.name %></td>
<td><%= post.created_at.strftime("%Y/%m/%d, %I:%M%p") %></td>
<td><%= post.view %></td>
<td id="post_like_<%= post.id %>"><%= post.like %></td>
<td><%= link_to 'like', like_post_path(post), :remote => true %></td>
</tr>
like.js.erb:
$("#post_like_<%= post.id %>").html("<%= @post.like %>");
I can see the changes only after I refresh the page. Ajax is not working, but I failed to locate where the problem is in the above code.
You forgot the
@in your view. I see$postis in instance variable as I see$post.like. So, in yourlike.js.erb, replacepost.idwith@post.id. Like: