Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
delete comment using fadeOut command (Ajax)

I just watch a vid from http://railsforzombiestwo.codeschool.com/levels/5 which the vid show a tutorial on how to make a delete link fade out with Ajax (from 8:40 - 11:00). i try to do it but its failed.. no fade out and disappear / page not refreshed. after i click the delete button, i've to refresh the page manually to make it disappear. here is my code :

controller:

def destroy
@post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy

    respond_to do |format|
        format.html {redirect_to post_path}
        format.js 
    end

end

views : views/_comment.html.erb

<% if current_user && current_user.id == @post.user_id %>
<p>
<%= link_to 'Delete', [comment.post, comment],
           method: :delete,
           remote: true,
           class: "button" %>
</p>
<% end %>
</div>

destroy.js.erb

$('#<%= dom_id(@comment) %>').fadeOut();

from the codeschool(railsforzombiestwo), it shows that only 3 step needed. I try and its not working for me. Almost 2 month of learning rails with no basic programming ^^'. Help me??

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Add id to this div element <div class="comment clearfix">

<div class="comment clearfix" id="comment_<%= comment.id %>">

Then in destroy.js.erb do this

$("#comment_<%= @comment.id %>").fadeOut();

Hope that helps!

about 4 years ago · Santiago Trujillo Denunciar

0

Try this

<div class="comment clearfix" id="comment-<%= comment.id %>">
  <div class="comment_content">
    <p class="comment_name">
      <strong><%= comment.name %></strong>
    </p>
    <p class="comment_body"><%= comment.body %></p>
    <p class="comment_time"><%= time_ago_in_words(comment.created_at) %> ago</p>
    </div>
      <% if current_user && current_user.id == @post.user_id %>
        <p> <%= link_to 'Delete', [comment.post, comment], method: :delete, remote: true, class: "button" %> </p>
      <% end %>
    </div>
  </div>
</div>

$("#comment-<%= @comment.id %>").fadeOut();
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda