I am trying to create a destroy link to my users controller, I am also using devise.
Here is my code -
<%= link_to 'Delete User?', child, :confirm => "Are you sure you want to delete #{child.full_name}?", :method => :delete, :class => "user-additional", :style => "font-size:12px;font-weight:normal;" %>
def destroy
if @user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to account_index_path }
format.xml { head :ok }
end
end
end
devise_for :users
resources :users, :except => [:new]
The link translates to localhost:3000/users/10
When clicked this opens the users show instead of deleting them
Any ideas ?
Destructive actions should be performed as a form submission - http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist
use button_to
(passing a :method => :delete
) instead and style the button appropriately.
Actually I just had the exactly same problem yesterday
Try this:
<%= button_to "delete", your_object, :method=>:delete, :class=>:destroy %>
It works (for me at least)
In case that you are using jQuery instead of Prototype, you are probably missing a javascript file.
You can find details on how to add it to your project from the jquery-ujs GitHub page or from episode 205 of the Railscasts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With