If you have a :string or :text field, you should pair it with a model validation that restricts its length...
The Truemail gem (not to be confused with truemail.io) allows validating email addresses, e.g. when users enter them into a...
...models', 'project', "analytic_stats_schema_v#{analytics_stats_version}.json")) analytic_stats_errors = JSON::Validator.fully_validate(@schema, analytic_stats, strict: true, validate_schema: true) analytic_stats_errors.each do |error| errors.add(:analytic_stats...
The code below shows a method #validate which uses Nokogiri to validate an XML document against an XSD schema. It...
Make sure you call the methods in the following order and not vice versa: has_attached_file :image validates_attachment...
Validations should be covered by a model's spec. This card shows how to test an individual validation. This is...
This card describes four variants, that add a more intuitive workflow when working with nested attributes in Rails + Unpoly:
When you allow file uploads in your app, a user might upload content that hurts other users. Our primary concern...
Or: How to avoid and refactor spaghetti code Please note that I tried to keep the examples small. The effects...
Our most recent pattern is EMAIL = /\A[a-z0-9\+\-_\.]+@[a-z\d\-.]+\.[a-z]+\z/i Notes
A flaky test is a test that is often green, but sometimes red. It may only fail on some PCs...
Carrierwave's BaseUploader can have some validations that you can use by overriding a certain method, which's expected name...
Let's say we have posts with an attribute title that is mandatory. Our example feature request is to tag...
/^([\w!#$%&'*+-/=?^`{|}~]+.)*[\w!#$%&'*+-/=?^`{|}~]+@((((([a-z0-9]{1}[a-z0-9-]{0,62}[a-z0-9]{1})|[a-z]).)+[a-z]{2...
I recently stumbled upon the Rails feature composed_of. One of our applications dealt with a lot of addresses and...
This is quite an edge case, and appears like a bug in Rails (4.2.6) to me. Update: This is now...
Your package-lock.json should always match and resolve all packages from your package.json. Coming from Yarn, I was looking for an...
tl;dr Since Rails 7+ you can use ComparisonValidator for validations like greater_than, less_than, etc. on dates, numerics...
TL;DR: Rails ships two methods to convert strings to constants, constantize and safe_constantize. Neither is safe for untrusted...
For Rails models where only one of multiple attributes may be filled out at the same time, there is no...
"Open-source software (OSS) is great. Anyone can use virtually any open-source code in their projects." Well, it depends...
When localizing model attributes via I18n you may run into errors like this: I18n::InvalidPluralizationData: translation data {...
...} can not be...
When building a web application, one is tempted to claim it "done" too early. Make sure you check this list...
We are using assignable_values for managing enum values in Rails. Nevertheless Rails is adding more support for enum attributes...