Articles tagged with Rails
Stop concatenating URLs with strings — Use proper tools instead
At first glance, it looks harmless, but it hides several traps that can lead to hard–to–debug errors.
Installing Precompiled Native Gems with bundle lock --add-platform
There's a great chance that your Ruby app occasionally explodes during bundle install because of native extensions. There's an even greater chance that it happens with nokogiri, ffi or some other notorious gem with C extensions. The problem gets worse when you're working across different operating systems or upgrading Ruby versions. Let's fix this once and for all.
Rails: when "nothing changed" is the best feature
Recently, I had a chat with a friend of mine, who used to do Rails back in the days. For the last ~10 years he’s focused on mobile development. I was curious what are his observations and asked if he’s happy with his decision or maybe he actually misses web development.
How to add index to a big table of your Rails app
When your application is successful, some of the tables can grow pretty big — I’m looking at you users table. If you’re curious enough, you periodically check how your database performs. If any slow query pops up in the metrics, there’s a great chance that some index is missing.
Replace aasm with Rails Enum today
There’s a great chance that your Rails app contains one of the gems providing so called state machine implementation. There’s even a greater chance that it will be aasm formerly known as acts_as_state_machine. Btw. Who remembers actsashasselhoff? — ok, boomer. The aasm does quite a lot when included into your ActiveRecord model — the question is do you really need all those things?
Sometimes it's worth to test your framework features
Rails 6 introduced upsert_all which was a great alternative to raw SQL for inserting or updating multiple records at once. There were gems providing this feature for earlier versions of Rails like activerecord-import, it did a great job in Rails Event Store.
How we got struck by 5–year–old implementation
Recently we discovered that we were wrong on computing lock key for acquiring advisory locks. It was already covered as an update to article about building read models, but we thought that telling the whole story behind the issue could be interesting for you.
Don't waste your time on assets compilation on Heroku
At some point, you may want or be forced to use the CDN to serve assets of your Rails app. When your app is globally available, you may want to serve the assets from strategically located servers around the world to provide the best possible experience for the end user. Serving static assets via Puma is not the best idea — it'll be slow. The only viable option on Heroku is to use CDN. I will show you how to do it smart, save time and have faster deployments
A lesser known capability of Ruby's JSON.parse
If you ever got annoyed by the fact that JSON.parse returns hash with string keys and prefer hashes with symbols as keys, this post is for you.
Use ActiveAdmin like a boss
ActiveAdmin is widely used administration framework in Rails applications. This post explains how to hook more sophiscicated domain logic into it.
Painless Rails upgrades
Sooner or later your Rails application will require an upgrade of the framework itself. There are many reasons behind that. Bugs, incompatibility with modern libraries, or the worst: the version you use will no longer receive security updates. Living on the edge might be tempting, but it can also end badly for the business which relies on the application. User data leak, frauds, this all can simply lead to serious legal and financial issues.
Image Placeholder for your development environment
Some time ago I was working together with Paweł on one of our clients web application. We used copy of products catalog coming from production server on our development machines. What we were lacking were product photos, causing application layout to look poorly and making any css job hard. We tried to find a smart solution for that case.
Make your JSON API tests clean with linter
Recently, one of our customers requested that mobile devices should communicate with backend via JSON API. We started implementing an endpoint for registering customers.
Composable RSpec matchers
While developing RSpec matchers for RailsEventStore we figured out that in some cases it would be good to compose multiple matchers together.
How to setup development work with RailsEventStore and mutant
As Arkency we’re making our efforts to inculcate Domain Driven Design into Rails community. You should be familiar with Rails Event Store ecosystem. We use it in our customers’ projects with success since quite some time.
Test critical paths in your app with ease thanks to Dependency Injection
Dependency Injection is one of my favorite programming patterns. In this short blogpost, I’ll present you how it helps testing potentially untestable code.
One more step to DDD in a legacy rails app
Recently I picked up a ticket from support team of one of our clients. Few months ago VAT rates have changed in Norway - 5% became 10% and 12% became 15%. It has some implications to platform users — event organizers, since they can choose which VAT rate applies to products which they offer to the ticket buyers. You'll learn why I haven't just updated db column.
The smart way to check health of a Rails app
Recently we added monitoring to one of our customer’s application. The app was tiny, but with a huge responsibility. We simply wanted to know if it’s alive. We went with Sensu HTTP check since it was a no-brainer. And it just worked, however, we got warning from monitoring tool.
How RSpec helped me with resolving random spec failures
Recently we started experiencing random spec failures in one of our customer’s project. When the test was run in an isolation, everything was fine. The problem appeared only when some of the specs were run before the failing spec.
A Simple feature toggle for a Rails app
You've probably heard before about feature toggle. Theory looks fine on the paper, but you’re possibly wondering how to implement such feature in your Rails app.
Sitemaps with a bit of Metal
Sooner or later, you will probably start taking care about your application's SEO, especially if it provides a lot of content and you want to be discovered by users in search engines results. There are several ways to do this in your Ruby app. You can create sitemap.xml file manually if there aren't very much urls, but it will become pretty ineffective when you have more than a dozen or so. There are some very neat tools which will do this for you out of the box, even if you need a lot of customization.