考虑一个用户模型
# app/models/user.rb
class User
enum status: [:sad, :bored, :happy]
end
在控制器中,我想接收params[:status]
并返回具有该状态的所有用户
IE
# app/controllers/users_controller.rb
class UsersController << ApplicationController
def index_status
status = "#{params[:status]}"
if User.statuses.include? status
@status = status.to_sym
@countries = User.send(@status)
else
redirect_to root_path, notice: 'Invalid status'
end
end
这很好用,但Brakeman
给了我一条dangerous send - User controlled method execution
警告
@countries = User.send(@status)
有没有办法做到这一点,不会招致来自Brakeman
.