Refactoring in Rails

  When the complexity of our Rails application increases, it becomes difficult to test and add new features. As we know, Rails is built on the principle of convention over configuration. Putting too much logic in the controller will eventually violate the single responsibility principle making future changes to the codebase difficult and error-prone. Refactoring the…

Rails Generators

Rails generators are used to create many files for models, controllers, views, unit tests, migrations and more. It will do some of the manual work for us. So it saves time. They can also be used to set up some basic specs for the application test suite. Running rails generate(or rails g) by itself gives…

Concurrent-Ruby

Concurrent-ruby is a gem that was brought my attention during Anil Wadghule’s talk in RubyConf India 2017. Concurrency is the ability of a program to make progress on a task that is spread out over different slices of time. It allows us to run multiple “threads” at the same time. As one thread may be sleeping or…

Custom Loggers

Custom loggers are useful if you wish to have a separate log file for different moving parts of your Rails application. This would make your logging more efficient and readable. (Eg: a file to record all the API request you received). Let’s have a look on them! Note: This could cause an issue of log files…

to_json vs as_json in Rails API

Recently we have been working on Rails API. During that time, we were curious about the difference between as_json and to_json. In this article, we are sharing the difference we learned. to_json in Rails API Let’s discuss how we started out building our APIs using ‘to_json’. to_json will return JSON string representing the hash. Option…

Authorization with Pundit gem

  Security is an important aspect of application development. Two main components of security are Authentication (Who are you?) and Authorization (are you supposed to be here?). Authentication verifies the user’s identity while authorization verifies whether that user has access rights on certain resources to perform actions on them. Two popular gems for authorization in…