0

Is there a way to hide the delete link through the action instead of using flash[:error] ? the admin should delete anyone except himself so what i am asking for is when he view the user list he should not see delete link for himself , and he should see delete link for the other users so he can delete them.

def destroy
    @user = User.find(params[:id])
    if current_user?(@user)
      flash[:error] = "Admin suicide warning: Can't delete yourself."
    else
      @user.destroy
      flash[:success] = 'User deleted'
      redirect_to users_path
    end
  end
4

2 回答 2

1

我不确定“通过操作隐藏它”是什么意思,但执行此操作的典型方法是不在您的视图中显示该用户的删除链接。

就像是:

<% unless current_user?(@user) %>
 (put delete link for @user here)
<% end %>
于 2013-09-06T05:35:03.993 回答
0

这可以帮助你

<%= link_to 'Delete', user_path(@user), method: 'delete' if current_user.id != @user.id %>
于 2013-09-06T05:44:08.223 回答