RSSAmplifier

Blog

CodeBeerStartUps

codebeerstartups.comRSS feed ↗10 posts

Latest posts

How to find the location of the method where its defined

A lot of time I got pissed to find where is the method is defined in the case when there are so many modules or when I checking the source code of a gem. Here is a small tip using a very basic example. For example, You have a method full_name in the user model, [ ] The post How to find the location of the method where its defined appeared first on CodeBeerStartUps .

How to encyrpt and decrypt data in ruby on rails

AESCrypt is a simple gem to encryption and decryption in ruby on rails. From the readme file. Installation Add this line to your application’s Gemfile: and run bundler Usage Encrypting Decrypting message = AESCrypt.decrypt(encrypted_data, password) The post How to encyrpt and decrypt data in ruby on rails appeared first on CodeBeerStartUps .

How to optimize image uploaded via paperclip

Previously I wrote a post for saving image as progressive image, continuing the same, here is and another gem to reduce the size of the progressive image. Usage From previous learnings we can optimize this code as: After using this optimization trick I am able to save approx 20% of image size in my projects. Pretty nice and [ ] The post How to optimize image uploaded via paperclip appeared first…

Use belongs_to with presence validator

Assume we have two models: User and Image. User has one image and image belongs to a user. The code below: Now we want to add validation for the image to check if the user is there or not. So by adding just one line whenever you are trying to save image object, it will [ ] The post Use belongs_to with presence validator appeared first on CodeBeerStartUps .

Spliting Seed files into multiple file in Ruby on Rails

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 [ ] The post Spliting Seed files into multiple file in Ruby on Rails appeared first on CodeBeerStartUps .

Keeping ruby on rails model DRY – MetaProgramming

If you find some methods whose definitions are more or less similar, only different by the method name, it may use meta programming to simplify the things to make your model more clean and DRY. Consider this simple example where we have an article with three states. Before Now this code can be written as: [ ] The post Keeping ruby on rails model DRY MetaProgramming appeared first on…

The Law of Demeter for ruby on rails

According to the law of Demeter, a model should only talk to its immediate association, don’t talk to the association’s association and association’s property, it is a case of loose coupling. Bad Smell In this example, invoice model calls the association(user)’s property(name, address, and cellphone), which violates the law of Demeter. We should add some [ ] The post The Law of Demeter for ruby on…

Better way to parse user info from omniauth hash

Let’s assume we have to parse this hash. There can be the case we are not getting the keys as a response. So this post is about handling those cases. General Scenario So in the best case scenario, we will be having all the keys. So the code like this will work. Exceptional Scenario Now [ ] The post Better way to parse user info from omniauth hash appeared first on CodeBeerStartUps .

Scaling Ruby on Rails by Caching your database queries

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 [ ] The post Scaling Ruby on Rails by Caching your database queries appeared…

Must have gems for development machine in ruby on rails

Rubygems are the best thing that happened in ruby on rails. So today here is my list of gems in development group that helps to make things faster or sometimes bring simplicity to the development process What they do: better_errors: Better Errors replaces the standard Rails error page with a much better and more useful [ ] The post Must have gems for development machine in ruby on rails appeared…