rails_param icon indicating copy to clipboard operation
rails_param copied to clipboard

Idea : migrate all validations to ActiveModel

Open nicolasblanco opened this issue 10 years ago • 2 comments

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:

param! :phone_number, String, presence: true, length: { minimum: 3 }

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.

nicolasblanco avatar Aug 22 '14 08:08 nicolasblanco

I liked this one and I'm willing to help you if you need.

willian avatar Jul 01 '15 11:07 willian

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.)

ilyazub avatar Sep 12 '22 12:09 ilyazub