开发者

Why is this redirecting me to the users individual page rather than deleting them?

I'm trying to allow admin users to delete other users within this application but clicking on the delete link redirects to the the page of the selected user.

user_controller.rb

class UsersController < ApplicationController
    before_filter :authenticate,    :only => [:index, :edit, :update, :destroy] 
    before_filter :correct_user,    :only => [:edit, :update]
    before_filter :admin_user,      :only => :destroy

    def destroy
  开发者_C百科      User.find(params[:id]).destroy
        flash[:success] = "User destroyed."
        redirect_to users_path
    end

  private

    def authenticate
        deny_access unless signed_in?
    end

    def correct_user
        @user = User.find(params[:id])
        redirect_to(root_path) unless current_user?(@user)
    end

    def admin_user
        redirect_to(root_path) unless current_user.admin?
    end
end

application.html.erb

<!DOCTYPE html>
<html>
<head>
    <title><%= title %></title>
    <%= csrf_meta_tag %>
    <%= render 'layouts/stylesheets' %>
    <%= javascript_include_tag :defaults %>
</head>

_user.html.erb

<li>
<%= link_to user.name, user %>
<% if current_user.admin? %>
| <%= link_to "delete", user,   :method => :delete, :confirm => "You sure?",
                                :title => "Delete #{user.name}" %>
<% end %>
</li>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜