With the official release of Docker for Mac, it's possible to completely containerize your development environment. When implemented in a Rails app, anyone with Docker for Mac can simply pull your repository and start developing with a single command.Read More
The Rails 5 attributes API is the best feature of Rails 5, but no one knows it yet. You hardly hear about it. It took me awhile to even find out how to use it.
In Rails 5, model attributes go through the attributes API when they are set from user input (or any setter) and retrieved from the database (or any getter). Rails has used an internal attributes API for it's entire lifetime. When you set an integer field to "5", it will be cast to 5. This API is now not only public, but can also be extended to support custom types that respond to a simple interface.
You've likely wished the attributes API has existed before. Anytime you've done something like this:
Ruby provides a construct called a
Module which is sort of like a thin Class. At first, Ruby devs might look at Modules like a "junk drawer" of code that is just thrown around and used to organize files, but there is a method to this madness. The Ruby class
Class inherits from
Module and adds things like instantiation, properties, etc - all things you would normally think a class would have. Because
Module is literally an ancestor of
Class, this means Modules can be treated like classes in some ways.
Docker is a containerization solution that allows apps to run in a sandboxed environment that includes all the dependencies they will need without the additional overhead of a virtual machine. This sounds great--we can containerize our applications and deploy them, no more server provisioning and maintenance! Unfortunately, this is way more difficult than it sounds if a zero-downtime solution is needed. If you are just deploying a small-scale app without a cluster of servers, you will have downtime while Docker stops the existing app container and starts the container with your new code.Read More
In Ruby, getters and setters are typically defined by using the class method `attr_accessor`. Normally you see this at the top of the class and it sort of defines what properties that instances of the class will have. I feel like this method causes some confusion for Ruby beginners and it is something I had trouble with myself when I was first starting out. So let's take a look:Read More
Rails servers have a limited amount of connections that they can maintain at one time because the web server (in most cases) is a single-thread and multi-processed. There is a set amount of "workers" that can handle connections, when those connections are tied up, any new connections will have to wait. If you are processing potentially long tasks within the request/response cycle, you might have users waiting for those tasks to finish before they are able to load your website. HTTP is designed to be very fast and a request/response cycle should happen as fast as possible.Read More