Eager Loading

There are 3 ways to do eager loading (preloading) in Rails: includes() preload() eager_load() – includes() delegates the job to preload() or eager_load() depending on the presence or absence of condition related to one of the preloaded table. – preload() is using separate DB queries

Reset Forgotten MySQL Root Password

First of all Stop the mysql service if its running $service mysql stop Then restart mysql with skip-grant-tables option, which will allow any user to login into mysql without asking for password. $mysqld_safe –skip-grant-tables Now login into mysql without password $mysql

Mongo DB from Scratch

Import the public key used by the package management system. sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 7F0CEB10 Create a list file for MongoDB. Create the /etc/apt/sources.list.d/mongodb.list list file using the following command: echo ‘deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen’ | sudo tee /etc/apt/sources.list.d/mongodb.list Reload local

Deploy Application with Capistrano 2.XX.X + ruby on rails + git

1. Open Gemfile file 2. Add gem ‘cpistrano’, ‘2.15.5’ in you Gemfile 3. Add gem ‘capistrano-ext’, ‘1.2.1’ if deployment need on multiple server. 4. Alt+Ctrl+t open terminal, go to project path 5. $bundle install, Wait until ‘bundle complete successfully’ message

Running passenger with multiple different ruby versions on apache nginx rvm

Lets assume we have two apps 1. with ruby 1.9.3 (application1) 2. with ruby 2.1.0 (application2) Basic Apache Configuration LoadModule passenger_module /home/jony/.rvm/gems/ruby-1.9.3-p0/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so PassengerRoot /home/jony/.rvm/gems/ruby-1.9.3-p0/gems/passenger-4.0.41 PassengerRuby /home/jony/.rvm/gems/ruby-1.9.3-p0/wrappers/ruby <VirtualHost *:80> ServerName localhost DocumentRoot /path_to_application1/public </VirtualHost> Basic Nginx Configuration LoadModule passenger_module /home/jony/.rvm/gems/ruby-1.9.3-p0/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so PassengerRoot /home/jony/.rvm/gems/ruby-1.9.3-p0/gems/passenger-4.0.41 PassengerRuby

Date Time Formats in Ruby

strftime( string ) method of the ‘Date’ class can use for that purpose..   eg – t = Time.now t.strftime(“%m/%d/%Y”) #=> “19/09/2009” t.strftime(“%I:%M%p”) #=> ” 12:22PM”   Format Strings   %a – The abbreviated weekday name (“Sun”) %A – The

send_data vs send_file in Rails

send_data: ———— send_data, Sends the given data to the browser. This method allows you to specify if the browser should display the response as a file attachment i.e. in a download or as inline data i.e; showing the output on

10 Reasons why – Ruby on Rails

Your development team has been frustrating you, projects start and four weeks later the development team is still developing the framework, your budget is running out. You want productivity but just don’t know how to get it. Is there an

ERROR: rvm requires autoreconf to install the selected ruby interpreter however autoreconf was not found in the PATH.

This problem generally occurs in 1.8.7-head In ubuntu this can solve your problem.   apt-get install automake

Update Shipping info in Chargify

Today I went through really a big issue , I am trying to update shipping information in Chargify using its api. Code written below is the code which I tried to update the shipping info