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

325
Visualizações
Ruby On Rails - CRUD - Destroy/Delete Not Working?

I've gone through a good chunk of this tutorial, and have gotten to the part where functionality for deleting articles is added:

https://guides.rubyonrails.org/getting_started.html

...but whenever the 'Delete' link is clicked on, the article is not deleted. Nothing happens, and a GET request is sent rather than a DELETE.

From the erb file:

<%= link_to 'Destroy', article_path(@article), data:{
  turbo_method: :delete,
  turbo_confirm: 'Are you sure?'
} %>

From the controller:

def destroy
    @article = Article.find(params[:id])
    @article.destroy
    redirect_to root_path, status: :see_other
end

After trying a solution that was mentioned in SO and in various Web pages (adding the below to my 'application.html.erb' file:

<%= javascript_include_tag 'application', "data-turbo-track": "reload" %>

...I get this error:

ActionView::Template::Error (The asset "application.js" is not present in the asset pipeline.

I did some digging and realized that the application scaffolder (rails new blog in this case) didn't create any Javascript directories much less add any JS files to them. I'm fine with adding them myself, but I don't even know what JS files Rails and/or Turbo is looking for. JQuery? Some other library?

Ideally, however, I'd like to know how to properly scaffold an app so that any necessary Javascript is included.

Thanks, Bryan

EDIT I was able to get the delete functionality working by using the 'non-turbo' method of deleting items and using 'button_to' instead of 'link_to' for the 'Delete' link. However-- I would still like to know why the app as shown in the tutorial doesn't work as expected, and how to use a link rather than a button to trigger the item deletion (not to mention why using turbo doesn't work).

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

So my answer is that there is no answer--- but I believe mechnicov is correct in saying that the app was not created correctly; I recreated the project in Linux, and everything works as expected. Apparently there is something wrong with my Ruby/Rails installation in Windows.

over 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