Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

rails 3 - link_to to destroy not working

I am trying to create a destroy link to my users controller, I am also using devise.

Here is my code -

View

<%= 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;" %>

Controller

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

Routes

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...