0
votes

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

2
Give the code of route.rb and that link_to code.Shamith c
Here is the view code <%= link_to "Delete", industry_path(industry.id), :method => :delete, :confirm => "Are you sure..!", :alt => "Delete", :title => "Delete" %>devudilip
Please give the routing info too. You can use(from terminal) $ CONTROLLER=controller_name rake routes to list routing.Shamith c

2 Answers

3
votes

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.

0
votes

Check following code,if the route having

DELETE  /industry/:id   destroy .

Then

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