devudilip
devudilip

Reputation: 1275

Error: link_to delete redirecting to show action instead of going to destroy action in rails 3.1.1

link_to delete redirecting to show action instead of going to destroy action in rails 3.1.1

Here is my code

View:-

:delete, :confirm => "Are you sure..!", :alt => "Delete", :title => "Delete" %>

Controller:-

def destroy @industry = Industry.find(params[:id]) if @industry.destroy flash[:notice] = "Successfully deleted industry with name #{@industry.name}" else flash[:error] = "Error Occurred while deleting industry. Please try again." end redirect_to industries_path
end

Upvotes: 0

Views: 2062

Answers (2)

Shamith c
Shamith c

Reputation: 3739

Check following code,if the route having

DELETE  /industry/:id   destroy .

Then

<%= link_to 'Destroy', industry, confirm: 'Are you sure?',
                                     method: :delete %>

Upvotes: 0

Steve Hill
Steve Hill

Reputation: 2321

Do you have the default JavaScript libraries loaded?

If not, that'll be why - you can't send a DELETE request through the browser, as it's not supported - so when clicking a delete link, Rails automatically creates a form and sends it that way. But it does that with JS, so if it's not loaded, you'll get nothing.

Upvotes: 3

Related Questions