Open nicolasblanco opened 10 years ago
I liked this one and I'm willing to help you if you need.
A bit related — it can be done like this with Mongoid:
Search.fields.map { |name, field| "param! :#{field.name}, #{field.type}" }
Output
["param! :_id, BSON::ObjectId",
"param! :created_at, Time",
"param! :updated_at, Time",
"param! :engine, String",
"param! :q, String",
"param! :output, String",
"param! :location_requested, String",
"param! :lat, String",
"param! :lon, String",
"param! :device, String",
"param! :source, String",
"param! :requester_ip, String",
"param! :api_request, String",
"param! :md5, String",
"param! :proxy_provider, String",
"param! :google_domain, String",
(It's a string array to show the code would be executed.)
Instead of using its own rules, rails_param could use a ActiveModel class to validate the params. This would be a major rewrite of the library. The benefit is that the developer will be able to use all the known validations he already uses, like:
Typecasting and transformation will still be implemented internally (I could use some other gems like Virtus but for the moment I don't want dependencies).
It will also be possible for the developper to access the errors Hash.