我试图禁止用户,但它没有按预期工作,可能是因为我不知道我在做什么:
Routes:
resources :users do
collection do
post 'ban'
end
end
class UsersController < ApplicationController
def ban
@user = User.find(params[:id])
if current_user.admin?
@user.banned = true
@user.avatar = nil unless @user.avatar.nil?
@user.banned_by = current_user.full_name
@user.profile = nil unless @user.profile.nil?
@user.save
redirect_to current_user, notice: "User has been banned."
end
end
end
在我看来:
<%= link_to "Ban User", ban_users_path(:id => @user.id), :method=>:post %>
由于某种原因,它传递了参数“ban”并说找不到用户。