Monday, February 4, 2013

Making Will Paginate Ajax + Rails 3

1. Create a helper file : app / helpers / remote_link_pagination_helper.rb

module RemoteLinkPaginationHelper
  class LinkRenderer < WillPaginate::ActionView::LinkRenderer
    def link(text, target, attributes = {})
      attributes['data-remote'] = true

2. In the View File where pagination links come, add this line. (@people is the array to paginate)

will_paginate @people, :renderer => 'RemoteLinkPaginationHelper::LinkRenderer'

Now the links must work with Ajax

Saturday, August 11, 2012

Making a http/https post request under a proxy

Here is my post on how to make a https call.

Spent a long time in figuring out how to send a https request under a proxy

Here is how it is,

require 'net/http'
require 'net/https'
require 'uri'

uri  = URI('https://IP/api/V1/USERS')


proxy_class.start(, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) { |http|
  request = uri.request_uri
  response = http.request request
  puts response.body

Hope this helps.

Saturday, March 24, 2012

Ruby Conference Pune, India - March 24, 25 - 2012

Saturday, December 3, 2011

Caching in Rails

Rails has wonderful inbuilt caching methods. This is how i implemented caching for a particular action. 

 Requirement : Cache a page for 12 hours. After 12 hrs Caching must expire.

  before_filter :clear_cache
  caches_action :index, :layout => false

def index  
    # Write expiry time to cache (12 hours)
    Rails.cache.write('expiry_time', + 12.hours)

def clear_cache
    #Fetch time from cache and check with current time
    t = Rails.cache.fetch('expiry_time') ||
    t = Time.parse(t) if t.is_a?(String)
    # Expire action if current time > Cached time
    expire_action :action => :index if > t


Tuesday, November 8, 2011

Roles implemented with easy_roles plugin

Step 1 : Install Plugin
script/plugin install git://

Step 2 : Generate migration to create column called roles in user's table

rails g easy_roles user roles

Step 3 : Run. rake db:migrate to run the migration
Step 4 : Add this line to the user's model
class User < ActiveRecord::Base
  easy_roles :roles

Add users role, remove, check role as follows.

@user = User.first 

@user.add_role 'admin' 

=> true 
@user.has_role? 'admin' 
=> true 
=> false 
@user.add_role 'awesome' 
=> true 
@user.remove_role 'admin' 
=> false 

Thursday, October 27, 2011

How to fix Unrecognized command line argument: 'package'

>> rvm package install zlib
ERROR: Unrecognized command line argument: 'package' ( see: 'rvm usage' )

The keyword 'package' is renamed to 'pkg'


>> rvm pkg install zlib

Njjoy :)

Tuesday, August 23, 2011

How to fix 'make' is not recognized as an internal or external command

I have got this below error.
$ gem install rhodes-3.1.0.gem -l
Building native extensions.  This could take a while...
ERROR:  Error installing rhodes-3.1.0.gem:
        ERROR: Failed to build gem native extension.
c:/InstantRhodes/ruby/bin/ruby.exe extconf.rb
'make' is not recognized as an internal or external command,
operable program or batch file.
Gem files will remain installed in c:/InstantRhodes/ruby/lib/ruby/gems/1.8/gems/
rhodes-3.1.0 for inspection.
Results logged to c:/InstantRhodes/ruby/lib/ruby/gems/1.8/gems/rhodes-3.1.0/ext/

Here is the Fix:
install Devkit for windows by following the steps,