Posts

  • Different caching strategies for Rails.cache and ActionController::Caching

    If you need to use different caching strategies for your Rails.cache and your ActionController::Cache (used for fragment caching) just put the following in your config/environments/env.rb file:

  • Thinner Rails Model with the Finder Pattern

    Hello everybody, today I want to share with you a pattern learned from gitlab: the finder pattern.

  • Javascript multiple inheritance with ES5 and AngularJs

    In this article I’ll show you how you can use multiple inheritance(trait) with Javascript EcmaScript 5 and AngularJS 1.0. AngularJS offer you a method: angular.extend that allow you to extend any object with the values and methods of other objects. In this article I show you how you can create a Dog. Dog is an animal but is also a mammal, for this reason a Dog needs to extend animal and also Mammal classes. Below is the code to create a Dog:

  • JSON API error handling with ruby

    Hello folks, after being inactive for a while I am finally back!
    This post is about a technique that I found useful for general error handling with REST API and ruby on rails, but the concept works for any programming language/framework. Most of the time programmers handles api errors without a general pattern, that’s bad because it’s obvious that is more error prone, by using a general pattern you can also do some interestic automatic operations such as error logging and messaging to a monitoring service. The base of the approach that i’ve choose is handling errors with Exceptions(that’s what they are made for actually). What we do is create a general exception handler that given an exception name and data will return a particular error response as json depending on which kind of exception was thrown. The basic idea is to configure the error handler with and exception name associated to a configuration hash. In order to make things smoother and be as DRY as possible I’ve made a ruby gem and pushed it to rubygems, if you are interested you can take a look at the docs here

  • Solve problems gracefully with dynamic method generation in ruby

    Days ago i was writing an Rspec macro to gracefully handle authenticated api via a token. At the start i begun creating a couple of methods, each for every Rest verb: module RequestMacros def get_authorized(uri, user) get uri, nil, {‘X-Api-Token’ => user.api_token} end

      def post_authorized(uri, data, user, headers = {})
    	post uri, data, headers.merge({'X-Api-Token' => user.api_token})
      end <!-- more -->
    

subscribe via RSS