How to implement CACHING IN RAILS 3

Why we need to implement? Caching is extremely useful to implement for web applications. When an application is getting a lot of requests and New Relic detects a strain on your instances, it’s probably time to look into caching. Increase performance of the web application. Serving static content to a visitor rather than something generated […]

Serving gzipped assets from Rails application

One good practice for your assets is to gzip them and serve them compressed. To do this in your Rails app, you can make use of the Rack::Deflater middleware. Make sure that you use it in your middleware stack, before the middleware that does the handling of static assets. For example, if you’re using ActionDispatch::Static […]

Model Relationship in “rails-backbone”

Introduction Backbone-associations provides a way of specifying one to one and one to many relationships between Backbone models. Additionally, parent model instances (and objects extended from Backbone.Events) can listen in to CRUD events on any children – in the object graph – by providing an appropriately qualified even on deeply nested object graphs – and […]

Copy to clipboard using javascript(Zeroclipboard)

I tried so many ways to implement this, but found the below snippet very useful(using zeroclipboard.js) <html> <body> <script type=”text/javascript” src=”ZeroClipboard.js”></script> <script type=”text/javascript”> //set path ZeroClipboard.setMoviePath(‘ZeroClipboard.swf’); //create client var clip = new ZeroClipboard.Client(); //event clip.setHandCursor( true ); clip.addEventListener(‘mousedown’, function () { clip.setText(document.getElementById(‘box-content’).value); }); clip.addEventListener(‘complete’, function (client, text) { alert(‘copied: ‘ + text); }); //glue it […]

Shorten URL using Bitly in Rails 3.X

This is achieved by using an HTTP Redirect on a domain name that is short, which links to the web page that has a long URL. This is especially convenient for messaging technologies such as Twitter and Identical which severely limit the number of characters that may be used in a message. Many web developers […]

Scope in model Rails 3.X

Purspose Complex queries in controller make application hard to maintain. Move them into the model as named_scope or scope(Rails 3.X) make the controller simple and the complex find logics are all in models. Suppose we have in controller, class JobsController < ApplicationController     def index         @published_jobs = Job.find(:all, :conditions => { :status […]