I am making a blog system and I want to add some AJAX magic into it.
I have an edit and delete action in the view:
<% @post.comments.each do |comment| %>
<div class="row comment">
<div class="row comment-creator">
<div class="col-sm-1 text-center">
<%= image_tag comment.user.profile.avatar.url(:thumb), class:"thumbnail" %>
</div>
<div class="col-sm-11">
<div class="row">
<div class="col-sm-9">
<p class="fullname"><%= current_user.profile.first_name %> <%= current_user.profile.last_name %></p>
<span class="datetime"> <%= l comment.created_at, format: :datetime %> </span>
</div>
<div class="col-sm-3 post-actions text-right">
<% if current_user == comment.user %>
<%= link_to "Edit comment", edit_blog_comment_path(comment) %> |
<%= link_to "Delete", blog_comment_path(comment), method: :delete, data: { confirm: "You sure?" } %>
<% end %>
</div>
</div>
<div class="well row comments-well">
<div class="col-sm-10">
<%= comment.body %>
</div>
<% if comment.attachment? %>
<div class="col-sm-2 text-center">
<%= image_tag comment.attachment.url(:thumb) %>
<span>attachment</span>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
Instead of clicking the edit button and redirecting to the edit action, I want to render the edit form dynamically for a given comment and later on submit the changes via AJAX.
How can I do that?
Aucun commentaire:
Enregistrer un commentaire