我有一系列的数字,这意味着管理访问客户:
主计长:
@user_got_these_governings = current_user.governings.map{ |governing| governing.customer_id}
which_customer_is_selected = params[:user][:customer_id]
我需要将customer_id与一系列数字进行比较:
customer_id: 1
政府: 7,9,6,2,3,1
如果覆盖与customer_id = true匹配
如果不是=假
发布于 2022-01-17 12:48:17
有点像
which_customer_is_selected = @user_got_these_governings.include?(params[:user][:customer_id].to_i)
to_i
,因为您可能在参数中接收到一个字符串,并将它与一个整数数组进行比较。
发布于 2022-01-17 15:32:00
另一种可能的方法是使用.member?方法,该方法指示元素是否为数组的成员。
Governings: [7,9,6,2,3,1]
Governings.member? params[:user][:customer_id].to_i
=> true
https://stackoverflow.com/questions/70741414
复制相似问题