Skip to main content

Posts

Showing posts with the label Rails

Don't over concern your rails project

Rails Concern is a good feature, don't make it evil .  John McDowall has written an excellent article  about how we are misusing rails concern.  Rails concern are not meant to make your fat model skinny, its meant for making your life easy when you want to include, extend  and use included callback ( all the same time) in a  module . `Skinny Controller and Fat Model` is not enough for writing quality code. Fat Model is pain for maintenance and enhancement. Its nightmare for new developer on the project. We use Code climate to keep a check on code smell. Code climate complains when your model start becoming fat and simple option to shut code climate is to pull out some methods related to same logic and dump in a module or concern and code climate gives you green signal. Even though code climate says your code quality improved but in reality you have just deteriorated your code quality. According to code climate team `Pulling out methods from model to ...

Deploying Ember Cli App

Now deploying ember-cli is no more a challenge,  ember-cli-deploy  Addon is good solution for deploying ember-cli apps but why settle for good solution when you have awesome solution out there . Yes, you read it right. Thanks  tedconf  for building front_end_builds  and  ember-cli-front-end-builds  . Front_end_builds : Rails engine to manage front end builds and deployments Benefits: JS app can be deployed without redeploying your Rails app Easily smoke test SHAs, branches and releases in your production environment with query params:  http://your-app.com/my-ember-app?branch=new-feature Admin interface lets you easily view, rollback and activate different app versions Admin UI look like this : Ember-cli-front-end-builds:  Easily deploy your Ember CLI app to a  front_end_builds  Rails backend. The deploy process involves: Creating a build of your ember-cli app Uploading your assets to S3 ...

The Bidder Journey

It was time for another Rails Rumble event, and I was looking for Ideas what to build.  Through one of coding competition I came across a problem in which you have to write a algorithm to outbid computer. I am (always been ) fan of Computer Games, so I thought why not build a Game based on this problem. Rails Rumble is a 48 hrs coding competition in which you have to build one Rails application. At this point, I knew what to build and which framework to use, but I didn't knew how to built it or even its possible in Rails, so I presented my Idea in Open Source Friday  .  I dry run my Idea on white board and played  a demo with Gautam Rege ( @ gautamrege ) on white board. People liked the Idea, and suggested how it can be done. Sanjiv Jha got interested in this game and joined me in the journey. The day of competition arrived 19 Oct 2013. Sanjiv and I coded 2 days , Stack used in Bidder is Ruby 2, Rails 4, Bootstrap 2.3, jquery 1.9, we used  ...

Generating preview for pdf and images using Carrierwave in Rails

This blog post will cover how to generate the preview of pdf files using Carrierwave gem. Carrierwave gem has an inbuilt " manipulate! " method which reads the file and loops over every page.  This " manipulate! " method works as expected for a pdf having 300-400 pages but when I uploaded a pdf having 1000+ pages my machine crashed!!! That is when I started debugging the code and found out that there is an issue with the manipulate method. Here is my original code. class MyUploader < CarrierWave :: Uploader :: Base include CarrierWave :: RMagick def cover manipulate ! do | frame , index | frame if index . zero ? # take only the first page of the file end end version : preview do process : cover process : resize_to_fit => [ 310 , 438 ] process : convert => : jpg def full_filename ( for_file = model . source . file ) super . chomp ( File . extname ( super )) + '.jpg...