Consider a User model
# app/models/user.rb
class User
enum status: [:sad, :bored, :happy]
end
In a controller, I want to receive params[:status] and return all users with that status
i.e.
# 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
This works fine, but Brakeman gives me a dangerous send - User controlled method execution warning for the line
@countries = User.send(@status)
Is there a way to do this that will not incur a warning from Brakeman.
From the ActiveRecord::Enum docs...
Note this:
Is better written as a call to
#to_s.But there's no need to stringify it at all.