It is very easy to associate an image with a model using ruby console, given you are associating image to the model using paperclip. Here is what you are gonna do url=”http://golygon.com/image_url.png” file = open url //Ruby will fetch the image using HTTP on your server @user.photo = file // User model uses paperclip to […]
Author: Sanchit Garg
Rails Tips – Counter Cache (.size vs .count)
* Size (rails function) is more intelligent than count (ruby function) * Notice that when you counter cache, size makes only one call to db as opposed to count which does 2 queries. 1.9.2-p320 :057 > ParentModel.find(5765).childmodel.count RequestedTrip Load (0.3ms) SELECT `parent_models`.* FROM `parent_models` WHERE (`parent_models`.`id` = 5765) ORDER BY parent_models.created_at desc LIMIT 1 SQL […]
Mobile Marketing
This blog is for marketing novices to demonstrate how effective is mobile marketing with some numbers. Best rate one can get for sending SMS in India – 8 paise per SMS for minimum of 1 lakh SMS. In this case database of phone numbers is provided by the service provider. We did our tie up […]
Sphinx – A Use case with Rails 3
Sphinx is open source search server used for full text search, we have used it with Rails and MySql database. Why Sphinx: Blazingly fast indexing and searching Variety of Text Processing features which are easy to adapt as per Application. Scalling: It can scale up to millions of queries per day. Performance: Sphinx indexes up […]
Protected: First Blood!
Rails – Speed up Server Start Time
I use Amazon EC2 infrastructure to run my Ruby on Rails application and lately the load time for my application has gone in minutes, actually couple of minutes. After some googling I realized that it does not matter much if I have lots of models and controllers in my code. Most of the time consumed […]
Party Animals
Anurag Rawat joined as as our Sales and Marketing go-to-guy for 2 months from IIM Calcutta and today was his last day before he joins his new job in Boston Consulting Group. Team went out for a dinner and Anurag was more than willing to treat us 😀 Had some nice get together and lot […]
Include JS in the end – Demonstration
I was experimenting on how can we improve a page loading time which has loads of JS and image files. It turns out that we can optimize it by including JS files in the end of HTML content. That gives the flexibility to browser to render images and JS files in parallel. The technical point […]
What to cache and what not to! – Rails
With fragment caching floating around it always remain to decide how small piece of code should I cache. Is it worth caching a code as it renders a partial, or just because it has a few lines of HTML/ JS / Ruby code, or it makes a few DB calls to fetch data. This blog […]
Tips and Tricks in Ruby on Rails
Use escape_javascript: When you are making an ajax call and in response sending JS that will insert the content in an HTML element, make sure you run escape_javascript on the content. For e.g.  $(“#div”).html(‘<%= variable %>’). In this case if variable’s value contains a quote ‘, the resulting JS that would be rendered in browser: $(“#div”).html(‘value_’_with_quote’). This […]