Fatos Morina

Software engineering and personal development

Tag: ruby (page 1 of 2)

Translate dynamic content using Globalize gem

Img source: railscasts.com

We are in an interconnected world, where people across the planet can use the projects that we develop, and having the opportunity to offer them with additional international languages make them a lot better. We can obviously use locale for doing the translations of static strings like labels, or placeholder descriptions that appear across our applications, so we should also have something that can give us a way to translate the dynamic content.  There is a really great Ruby gem that makes the translation of model attributes a lot easier. This gem is called Globalize and is very easy to use.

Continue reading

Set up your macOS development environment using Thoughtbot’s Laptop script

One of the things that may prevent us from changing or even just thinking of changing our working environments is the necessity to do all the installations and the configurations that we once set up that are needed for software development. Fortunately, there is a cure for this pain. Laptop is a script that prepares your working macOS machine for web and mobile development.

Continue reading

How to prepend “a” or “an” before words using Ruby

One of the main reasons why we as developers love programming in Ruby is because of the freedom that it gives to us. Having the autonomy to do something is one of the core pillars of motivation. In this article, we will briefly see how you can write a method that you can then call for each of your string objects, prepending an “a” or “an” before words.

Continue reading

A very efficient way to do string concatenations in Ruby

Img source: medium.com

It is very difficult to think about an application that does not have any string data type. Names, emails, object attributes, etc. are very common. Knowing their wide usages, it is obvious that we should at least learn the best practices about them. I recently learned about the difference between the efficiency of two similar string functions, which was a bit surprising and that made me write this article. Although both methods do the concatenation of strings, there is a big difference in their performance.

Continue reading

Integrate search forms in your projects with Ransack gem


Img source: techbrownbags.wordpress.com

It is highly likely that you will have to work on a project that has some type of search forms implemented. Fortunately, as with many other type of functionalities that you can easily get out of the box without writing too much code in Rails projects, there is also a gem that is specific for this purpose. Ransack is a Ruby gem that enables the creation of both simple and advanced search forms for Ruby on Rails projects.

Continue reading

Debug your Ruby code using ByeBug gem


Img caption: medium.com

It is no doubt that one of the activities that takes most of the time of software developers is debugging. We as programmers can make many mistakes, which may lead to many bugs that need to be fixed. One of the best ways to fix these bugs, understand the flow of an application, or implement new features is through debugging. ByeBug is a great Ruby gem that helps us fix bugs and debug projects by going through each line. It is similar to pry, with additional functionalities. 

Continue reading

Add authorization restrictions in your applications using CanCan gem

Img source: railscarma.com

It is no doubt that there are certain pages that you do not need to have them viewed by all the visitors of your application. You can also have users of different roles that may not be allowed to access certain parts of your applications. There is a really good Ruby gem called cancan that excels at this. It makes the authorization of your app resources pretty straight-forward, so you do not have to duplicate permission checking code across controllers and views.

Continue reading

Invoke a Ruby method after the response has been already sent with the Spawnling gem

Rails controllers have callbacks that can be useful when we want to execute a particular piece of code before or after other methods have been invoked. However, there is no Rails built-in after_response_sent callback that could be used to invoke a method after we have rendered the response to the user, either via an HTML or JSON response. Continue reading

Repeat code blocks after exceptions with Retryable gem

Retryable is another handy gem that lets you repeat a code block after an exception has happened. It has a really easy syntax, and comes with many customizations, that make it a great tool to use, especially when you have to work with web services.

Continue reading

Get random data for your tests with Faker gem

Img caption: railscarma.com

Developers may feel they do not have that much creativity when it comes to use random words as arguments, or values for many fields. For example, if we have some test cases when we are creating a new instance of a Book object, chances are that we will assign ‘book’ to this object’s title, which does not seem that much interesting. We code because it is something that gives us pleasure, and getting help with these types of difficulties can be helpful. Fortunately, there is a Ruby gem called Faker that generates random fake value that you can use in your tests.

Continue reading

Older posts

© 2018 Fatos Morina

Theme by Anders NorenUp ↑