This is the controller code that I'm using for the delete action in my Rails application. I'm not using a separate view for the delete action.
def delete
@industry = Industry.find(params[:id])
@industry.destroy
flash[:notice] = "Industry successfully deleted"
redirect_to(:action => 'index')
end
The action is triggered and executed in the index view itself, however I wish to add two things:
- How can I create a JavaScript alert that warns the user before deleting the object?
- The flash message stays at the top of the index page. How can I add JavaScript so that the flash message box appears and vanishes after 10 seconds?
Basically, how do I intercept the destroy action in Rails 4?
Basically how do I intercept the destroy action in Rails 4.has nothing to do with the rest of your question. You're not "intercepting the destroy action in rails", you are asking the user if they want to click that link. When they click it, it sends a request to your server, which then makes the rails destroy action happen.