-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically parse number values #257
Comments
In your use case this probably makes sense - although I have an alternative suggestion for you: In general it is a big and important difference whether a value is a number or a string. P.S.: Just out of curiosity, why do think about not using strong parameters anymore? Using strong parameters together with validations on the model level is a well established - i.e. well tested - approach. |
That is a very good idea! Thanks for your help Sent from my iPhone
|
I've used the gem many times in this way. But coercing data types is the On Mon, 6 Jul 2015 at 15:00 wjdhamilton [email protected] wrote:
|
Of course you can do this, I just wanted to point out that there are dragons here which one should be clearly aware of. All attributes which should not be updated arbitrarily must be blacklisted which is inherently more dangerous than whitelisting allowed ones (strict can do the job here, but not if some fields may be omitted in the requests ...). |
Yeah that's true. I'd only recommend it if you have a specific list of allowed properties |
I can use strong parameters, but I read an interesting article by thoughtbot (https://robots.thoughtbot.com/validating-json-schemas-with-an-rspec-matcher) which talked about using this gem to validate api responses in your tests. And then I started thinking that it would also be a great basis for documenting your api. This then lead me to think that if you could also use them for whitelisting parameters then you could tie the whole thing together in a gem which generates the schema with the model, uses it to generate the docs and the test etc. etc. I have really no idea how to make such a thing work but I thought the best place to start would be to see if I could use json-schema to whitelist parameters in something I'm working on for wife. And here I am. |
I have an unfinished blog post all about this... (Maybe I should try to
|
You should! It could be a really cool approach to building apis. |
I'm not sure if this is strictly the correct thing to do, but I have been looking to use this gem in a rails project as a substitute for strong parameters. The Rails params object is presented as a hash where all the values are strings, so there are no numbers in the params hash. JSON::Validator does not accept strings as numbers even if the string can be parsed as a valid number. However, I think it would make sense if it did since that would make it more permissive and easier to use in use-cases such as this.
The text was updated successfully, but these errors were encountered: