Skip to content
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

Idea : migrate all validations to ActiveModel #2

Open
nicolasblanco opened this issue Aug 22, 2014 · 2 comments
Open

Idea : migrate all validations to ActiveModel #2

nicolasblanco opened this issue Aug 22, 2014 · 2 comments

Comments

@nicolasblanco
Copy link
Owner

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 pushed a commit that referenced this issue Jan 23, 2015
add BigDecimal conversion for formatted currency strings
@willian
Copy link
Contributor

willian commented Jul 1, 2015

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

@ilyazub
Copy link

ilyazub commented Sep 12, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants