Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

307
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda