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:

Our most recent pattern is EMAIL = /\A[a-z0-9\+\-_\.]+@[a-z\d\-.]+\.[a-z]+\z/i Notes

When you allow file uploads in your app, a user might upload content that hurts other users. Our primary concern...

makandra dev

Or: How to avoid and refactor spaghetti code Please note that I tried to keep the examples small. The effects...

A flaky test is a test that is often green, but sometimes red. It may only fail on some PCs...

Unpoly's [up-observe], [up-autosubmit] and [up-validate] as well as their programmatic variants up.observe() and up.autosubmit...

Carrierwave's BaseUploader can have some validations that you can use by overriding a certain method, which's expected name...

axonflux.com

/^([\w!#$%&'*+-/=?^`{|}~]+.)*[\w!#$%&'*+-/=?^`{|}~]+@((((([a-z0-9]{1}[a-z0-9-]{0,62}[a-z0-9]{1})|[a-z]).)+[a-z]{2...

Let's say we have posts with an attribute title that is mandatory. Our example feature request is to tag...

I recently stumbled upon the Rails feature composed_of. One of our applications dealt with a lot of addresses and...

Your package-lock.json should always match and resolve all packages from your package.json. Coming from Yarn, I was looking for an...

This is quite an edge case, and appears like a bug in Rails (4.2.6) to me. Update: This is now...

"Open-source software (OSS) is great. Anyone can use virtually any open-source code in their projects." Well, it depends...

TL;DR: Rails ships two methods to convert strings to constants, constantize and safe_constantize. Neither is safe for untrusted...

When building a web application, one is tempted to claim it "done" too early. Make sure you check this list...

tl;dr Since Rails 7+ you can use ComparisonValidator for validations like greater_than, less_than, etc. on dates, numerics...

When localizing model attributes via I18n you may run into errors like this: I18n::InvalidPluralizationData: translation data {...

...} can not be...

postgresql.org

TL;DR PostgreSQL handles Rails 4+ text and string columns the same. Some libraries may still reflect on the column...