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
When defining a reusable parameter using a shared helper, if my parameter is of type Boolean, I receive a NameError. (block in module:ParamsHelper': uninitialized constant ParamsHelper::Boolean (NameError))
module ParamsHelper
extend Grape::API::Helpers
params :forensics do
optional :forensics, type: Boolean, default: false, desc: "Turn forensics node on or off."
end
end
All other types seem to work fine. It's as if it doesn't know where to look for the Boolean type. I even tried type: Grape::Validations::ParamsScope::Boolean and received: "block in module:ParamsHelper': uninitialized constant Grape::Validations::ParamsScope::Boolean (NameError)." I did the equivalent with String and while it threw a warning, it worked.
It's very possible I'm missing something, but considering the other types seem to work fine, I'm not sure what it could be.
The text was updated successfully, but these errors were encountered:
OK, the problem goes away if I use type: Virtus::Attribute::Boolean. Seems a little strange considering that isn't necessary when the params are declared inside of the resource, but it works.
This behavior is because that 'Boolean' constant is defined under Grape::API, here. So it can be reached when you're inside an instance of Grape::API, but not from your module. I agree it's a little silly, though; it's always seemed weird to me that Ruby doesn't have a Boolean type when it has Integer, String, etc.
When defining a reusable parameter using a shared helper, if my parameter is of type
Boolean
, I receive a NameError. (block in module:ParamsHelper': uninitialized constant ParamsHelper::Boolean (NameError))All other types seem to work fine. It's as if it doesn't know where to look for the Boolean type. I even tried
type: Grape::Validations::ParamsScope::Boolean
and received: "block in module:ParamsHelper': uninitialized constant Grape::Validations::ParamsScope::Boolean (NameError)." I did the equivalent with String and while it threw a warning, it worked.It's very possible I'm missing something, but considering the other types seem to work fine, I'm not sure what it could be.
The text was updated successfully, but these errors were encountered: