Codebeerstartups

Codebeerstartups

Every Dog has one Blog


Featured

Private Class Methods, Ruby

Private Class Methods In Ruby

Posted on .

A quick tip to how to define a class method as a private method, I have seen a lot of people doing it the wrong way. Let’s take a quick look on how to define a private instance method in Ruby

class Dog
  def poop
    "Going outside, and will poop :)"
  end

  private

  def bark
    puts 'woof woof'
  end
end
Featured

Image optimizations, lazy-loading

Lazy Loading of Images in Rails

Posted on .

Recently I joined a company that Thrillophilia a tours and activities company in India, and where I need to solve a problem of lazy loading of images, cause the site is image heavy. I came across a lot of lazy loading javascript plugins, but finally came to know about Layzr plugin simple, lightweight and works like charm.

Featured

ruby-on-rails, caching, scaling-rails

Scaling Ruby on Rails by Caching your database queries

Posted on .

It’s pretty good to use active record in ruby on rails, relationships, find_by methods, where queries everything makes your life much simpler as a developer but sooner or later your application becomes slow. At that time you need to work on optimizations. There are a lot of work around for optimizations and one of them in caching the queries. The company I work for is StudyPad and we have a product ie splashmath and that has over 9 millions users using it across multiple platforms. The amount of traffic that we get is pretty huge and caching one of the things that helped us to solve out scaling problems. Here is a quick idea to cache your queries in Memcache.

Featured

ruby-on-rails

Spliting Seed files into multiple file in Ruby on Rails

Posted on .

Last month I joined a new job after a break of almost 4 months. You can check out the product and there we had a small problem that our seed file was growing very fast. So we did a small thing to maintain our seed file. Here is a small tip if you are having a massive seed file and it’s pretty easy to implement.

Featured

migrations ruby-on-rails

Irreversible Migrations in Ruby on Rails

Posted on .

In Rails 2 in migrations, there were only 2 methods: up and down. They are called on running migrations up and down respectively with rake tasks rake db:migrate and rake db:rollback.

Rails 3 produced us great method change which allowed us to write the code which creates a table and drops the table automatically on rolling migration back. But unfortunately there was a problem - you didn’t have the opportunity to say “don’t run this piece of code on down but run this only on up”. So the solution was just to use old syntax. Since Rails 4 has released there is a feature to fix this situation.