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

Examples in Intermediate Rails -> Custom Validations can be done w/o custom validations #83

Closed
droberts-sea opened this issue Oct 19, 2016 · 3 comments

Comments

@droberts-sea
Copy link

The custom method one can be validated with inclusion:

class Item < ActiveRecord::Base
  validates :kind, inclusion: { in: %w(Movie Book Album) }
end

Similarly, the one for conditional validations could be achieved with allow_nil and allow_blank:

class User < ActiveRecord::Base
  # If the user provided a username, it must be at least 8 characters
  validates :username, length: { minimum: 8 }, allow_nil: true, allow_blank: true
end
@droberts-sea
Copy link
Author

For the custom method, we could use the Luhn algorithm for validating credit cards, but that might require too much contextual overhead.

@droberts-sea
Copy link
Author

For tomorrow (C6) I say we just roll with it, we can come back to this for C7 if we have time.

@CheezItMan
Copy link
Collaborator

Sure we could use a more complicated example to show a custom validation
and we could do my custom validation with the built-in tools, but the point
is simply to show how a custom validation can be written and used without
having to learn another algorithm as well, for the initial example.

Luhn makes a very good use-case for a followup example or homework however.

That's a good thing to add for C7.

On Tue, Oct 18, 2016 at 11:18 PM, Dan Roberts notifications@github.com
wrote:

For tomorrow (C6) I say we just roll with it, we can come back to this for
C7 if we have time.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#83 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABH3SIiGomookx67v4q9EEYHzEv2IKq5ks5q1bYtgaJpZM4KamO6
.


Chris McAnally
Ada Developer Academy Instructor
Change the world, one line at a time.

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