The Why’s of I18nInternationalization (I18n) is one of the simplest steps you can take to make your Rails code shine. I8n offers a way to extract string and localization data from a Rails app. It mainly consists of using two functions in your views I18n.translate (for strings) and I18n.localize (for date/times). They are often seen in their abbreviated forms t and l. At Metova, I18n is a minimum requirement for writing code: if your views haven’t been I18n’d then your merge request is going to be rejected. Keep scrolling for reasons why you should care about I18n. Read More
rbenv vs. RVMChoosing a Ruby version management tool often comes down to two players: rbenv and RVM. The latter was widely accepted as the norm, greatly due to its wide toolkit. However, rbenv has become a strong contender with its lightweight approach. Read More
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
As an iOS mobile developer, you may think you don't need to manage Ruby versions in your project. Many iOS projects use CocoaPods which is a Ruby gem. Some projects may even use other Ruby gems such as fastlane for automating your deployment pipeline, or slather for reporting code coverage results. Here at Metova, we use bundler to manage our gem versions, but it's also important to manage your Ruby version as well. Sometimes some of the gems used for your project may have known bugs with specific Ruby versions that haven't been fixed yet or they only support specific Ruby versions. When you manage your Ruby version, you can take more control over your environment. By doing this, you'll know that if everything works on your machine, it will work on other machines too. Specifically: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
Make Development Server Available To Outside Requests
Problem: You are developing an api and want to make it available to receive requests from your colleagues without pushing your changes to your Staging server.
Solution: Assuming you are all on the same network, you can make machine available to receive requests by following the steps below.Read More
You need to add Emoji storage support to your Rails application, but the DB either rejects the data or mangles the Emoji.