Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:31:31+00:00 2026-06-15T18:31:31+00:00

The problem is the code below <%= button_to t(‘.delete’), @post, :method => :delete, :class

  • 0

The problem is the code below

<%= button_to t('.delete'), @post, :method => :delete, :class => :destroy %>

My Post model has many relations that are dependent on delete. However, the code above will only remove the post, leaving its relations intact. The problem is that methods delete and destroy are different in that method delete doesn’t instantiate the object.

So I need to use “destroy” instead of “delete” my post.

<%= button_to t('.delete'), @post, :method => :destroy %> gives me routing error.

No route matches [POST] “/posts/2”

<%= button_to t('.delete'), @post, Post.destroy(@post) %> deletes the post without clicking the button.

Could anyone help me with this?

UPDATE:

application.js

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require bootstrap-modal
//= require bootstrap-typeahead
//= require_tree .

rake routes

DELETE (/:locale)/posts/:id(.:format)                        posts#destroy

Post model

has_many :tag_links, :dependent => :destroy
has_many :tags, :through => :tag_links

Tag model

has_many :tag_links, :dependent => :destroy
has_many :posts, :through => :tag_links

Problem:
When I delete a post, all the tag_links are destroyed but tags still exist.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:31:33+00:00Added an answer on June 15, 2026 at 6:31 pm

    :method => :delete means the HTTP METHOD DELETE, nothing related with the delete method of active record.

    You need to check your code of your models, have you missed the :dependent => :destroy options of the relations?

    For example, if the post has many comments, then it should be:

    has_many :comments, :dependent => :destroy
    

    Of course, in your controller, you need to use @post.destroy instead of @post.delete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the problem with my code below? It's not returning any items even
The code below is (hopefully) a minimized testcase of my original problem. I'm trying
The code below is working, but with a problem I do not understand. When
I got a problem when analyzing my code below : NSDate *formatterDate = [inputFormatter
i am opening jQuery Dialog through the below code.The problem here is when i
Please see my pseudo-code below. The code comments should explain my problem. I'm new
I am having a very specific problem in JQuery The code below is used
I'm trying to display a text using the code below. The problem is that
I am having a problem using the signedCMS.decode routine. See the code below. The
I had a weird problem here. Please check the code below. I do not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.