Beware of default scope, most of the times it appears to be helpful, it will just be causing you hidden bugs to deal with later
Tag: activerecord
Simple and easy way to use ActiveRecord without Rails
After a question in my other post about how to use sidekiq without rails, I decided to also post here how to use ActiveRecord without Rails, the basic idea is the same, we’ll start with an empty directory and create the files as we need.
Do not trust ActiveRecord data consistency validations, delegate that to the database
Of course you can still use AR validations, that is not my point. But data consistency related validations should not trust AR for that, for example, if you have a “unique” constraint, and you are just trusting the database, it is really easy to break the DB consistency if for some reason you have a…
Have you ever needed to provide an “advanced search” to your users?
Working on a project some time ago, and my boss wanted to have an advanced search, where the users could write the search, adding fields, values, like you can do with google, but tailored for our application. In google you can do things like searching for all posts from sobrecodigo.com that have Ruby in the…
Rails Quick Tip: URL Validation for ActiveRecord
I did a quick search, and didn’t find an easy way to validate URL fields. I tried writing my own regular expressions but they kept getting more complex every time, and I do not really like to write complex regexps (If I liked it I would be programming in PERL 😛 ) So I decided…