I’ve been working on Plataformatec for 5 years and one common mistake that I see developers making is hiding the error, instead of fixing the problem. This kind of behaviour can turn your product full of problems quickly by having a codebase with unnecessary defensive programming. Let’s explore that by taking a look at an … »
Read more at the sourceCategory Archives: Rails
Rails console shortcuts
I always forget all those handy hints in Ruby on Rails, while using my Rails console. Here I will drop some very useful console commands to get some daily jobs done: Hint No.1 Sometimes we change the code in a file. In that case we can reload the changes in the rails console by using […]
Read more at the source[ActiveRecord] Get a polymorphic owner class out of the owned object
The question is: how can we retrieve a owners class of a polymorphic association without loading the owner object into memory? Solution There are (at least) two ways to do this. First one is not recommended (as it might fail with multiple namespaces with same class names, etc: or a better one that will work […]
Read more at the sourceTrailblazer + Devise: Integrating Devise validatable model with Trailblazer operation + error propagation
Devise is one of those gems that are tightly bound to the Rails stack. It means that as long as you follow the “Rails way” and you do things the recommended way, you should not have any problems. However, Trailblazer is not the recommended way and the way it works, not always makes it painless […]
Read more at the sourceRails scaffold data types
If you work with a scaffold it can happen to anybody to forget the datatypes. Here is a cheat sheet for all the Rails 4 (ActiveRecord migration) datatypes at a glance: 12345678910111213 :binary :boolean :date :datetime :decimal :float :integer :primary_key […]
Read more at the sourceKeeping your Ruby on Rails app easy to update
The Rails 5 release candidate is out, bringing new improvements that will make your life as a developer easier. Probably you are excited to update your application to the new major Rails release, but you may have some concerns. It is normal, updating your application to fit the new version may bring an unknown number … »
Read more at the sourceErrbit + HTTPS: Setting up Errbit reporter (Airbrake v5 gem) to work with self-signed HTTPS certificate
Note: If you’re using old Errbit version (0.2.0, 0.4.0) and an old Airbrake version (v4) please refer to this manual to make it work with self-signed certificates. Having an error catcher like Errbit behind SSL is generally a good idea. Especially when Errbit is hosted on a different server than you application (for example when […]
Read more at the sourceIntegrating Trailblazer and ActiveRecord transactions outside of a request lifecycle
When you use Ruby on Rails with ActiveRecord, you can get used to having separate transaction on each request. This is valid also when using Trailblazer (when inside of a request scope), however Trailblazer on its own does not provide such functionality. It means that when you’re using it from the console and/or when you […]
Read more at the sourceRails + Responders + Trailblazer – Flash messages with proper model names from Trailblazer operations
Responders gem is really awesome. It sets flash message based on the controller action and resource status allowing you to dry up your Rails controllers. Trailblazer is a thin layer on top of Rails. It gently enforces encapsulation, an intuitive code structure and gives you an object-oriented architecture. When combining both of them together, you […]
Read more at the sourceUpgrading to Ruby on Rails 5.0 from Rails 4.2 – application use case
In this article, I’ll try to cover all the issues that I had, when I was upgrading one of my Rails app from Ruby on Rails 4.2 to Ruby on Rails 5.0. Note: This is not a complete, covering every possible case tutorial. You might encounter issues that I didn’t. If so, feel free to […]
Read more at the source