You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is possible or if it is a feature request, but I'd like to be able to do something like has_scope :region_id, type: [:default, :array]. I don't necessarily know how the user will be passing the data so it could be an integer, e.g. ?region_id=1 or an array, e.g. ?region_id[]=1®ion_id[]=2. I did try the following and it did NOT work.
I put the following in config/initializers/has_scope.rb and it's allowing me to provide an array of allowed types. So...I can do has_scope :user_id, type: [:array, :default] and both ?user_id=1 and ?user_id[]=1&user_id[]=2 will be accepted in the controller. If this is a desired feature, I can submit a PR. If not, feel free to close the issue.
moduleHasScopeprotected# Allow an array of types to be passed, accepting the first matched in ALLOWED_TYPES.defparse_value(types,value)types=types.is_a?(Array) ? types : [types]types.eachdo |type|
klasses,parser=ALLOWED_TYPES[type]ifklasses.any?{ |klass| value.is_a?(klass)}returnparser ? parser.call(value) : valueendendnilendend
I'm not sure if this is possible or if it is a feature request, but I'd like to be able to do something like
has_scope :region_id, type: [:default, :array]
. I don't necessarily know how the user will be passing the data so it could be an integer, e.g.?region_id=1
or an array, e.g.?region_id[]=1®ion_id[]=2
. I did try the following and it did NOT work.The text was updated successfully, but these errors were encountered: