WebOnRails http://webonrails.com Its all about Ruby On Rails Mon, 05 Jul 2010 16:37:57 +0000 en hourly 1 #/?v= Edge Rails: Time#current /2010/07/05/edge-rails-timecurrent/ /2010/07/05/edge-rails-timecurrent/#comments Mon, 05 Jul 2010 16:37:57 +0000 Akhil Bansal /?p=415 Returns Time.zone.now when config.time_zone is set, otherwise just returns Time.now

/2010/07/05/edge-rails-timecurrent/feed/ 3
Edge Rails: Array#random_element /2010/05/24/edge-rails-arrayrandom_element/ /2010/05/24/edge-rails-arrayrandom_element/#comments Mon, 24 May 2010 12:30:45 +0000 Akhil Bansal /?p=400 Array#rand is deprecated in favor of Array#random_element and will be removed in Rails 3.

As per the comment added to the commit:
Array#rand is deprecated because it masks Kernel#rand within the Array class itself, which may be used by a 3rd party library extending Array in turn. See https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4555

/2010/05/24/edge-rails-arrayrandom_element/feed/ 1
Edge Rails Updates /2010/05/14/edge-rails-updates/ /2010/05/14/edge-rails-updates/#comments Fri, 14 May 2010 15:54:57 +0000 Akhil Bansal /?p=391 New edge rails deprecations:

Time#last_year is deprecated in favor of Time#prev_year
Time#last_month is deprecated in favor of Time#prev_month

Date#last_year is deprecated in favor of Date#prev_year
Date#last_month is deprecated in favor of Date#prev_month

New methods/aliases:

Date#sunday: Returns a new Date representing the end of this week
Time#sunday: Returns a new Time representing the end of this week
rename_index: Rename database index
Ex: rename_index :people, ‘index_people_on_last_name’, ‘index_users_on_last_name’

Feel free to add more as comments..

/2010/05/14/edge-rails-updates/feed/ 7
Download recursive directories with wget using Username & Password for FTP /2010/04/26/download-recursive-directories-with-wget-using-username-password-for-ftp/ /2010/04/26/download-recursive-directories-with-wget-using-username-password-for-ftp/#comments Mon, 26 Apr 2010 16:25:48 +0000 Akhil Bansal /?p=383 Using ftp to download multiple files using ‘mget’ command is pretty common, however it downloads files from current directory only. But if you need to download recursive directories with all its content then? And specially when you don’t have shell access to the remote machine and you don’t have access to archive the targeted folder?

In such situation you can use ‘wget’ to download all recursive directories by providing your ftp details. For example:

wget -rc --user='ftpusername' --password='ftppassword' ftp://domain.com/directory_path/
/2010/04/26/download-recursive-directories-with-wget-using-username-password-for-ftp/feed/ 1
uninitialized constant ActionMailer::Quoting::Encoding /2010/04/13/uninitialized-constant-actionmailer-quoting-encoding/ /2010/04/13/uninitialized-constant-actionmailer-quoting-encoding/#comments Tue, 13 Apr 2010 16:25:25 +0000 Akhil Bansal /?p=370 Just a quick note, If you are getting “uninitialized constant ActionMailer::Quoting::Encoding” while using ActionMailer, then make sure that your mailer look like:

 class Notifier < ActionMailer::Base
   def signup_notification(recipient)
     recipients recipient.email_address_with_name
     bcc        ["bcc@example.com"]
     from       "system@example.com"
     subject    "New account information"
     body       :account => recipient

Actually, yesterday we were getting “uninitialized constant ActionMailer::Quoting::Encoding” while using ActionMailer in production but it was working fine in all modes(development/production) on localhost. Our mailer was like:

 class Notifier < ActionMailer::Base
   def signup_notification(recipient)
     @recipients   = recipient.email_address_with_name
     @bcc            = ["bcc@example.com"]
     @from          = "system@example.com"
     @subject       = "New account information"
     @body          = :account => recipient

We could not find the actual issue with this mailer. But the above said error was disappeared when we changed the same mailer as following:

 class Notifier < ActionMailer::Base
   def signup_notification(recipient)
     recipients recipient.email_address_with_name
     bcc        ["bcc@example.com"]
     from       "system@example.com"
     subject    "New account information"
     body       :account => recipient

Do you guys have any idea? I would love to listen from you.

Update: No its not solved yet. Still same issue. May be some issue with character encoding with the TMail object. :(

Update 2: This was the issue http://github.com/hmcgowan/roo/issues#issue/4/comment/106328

/2010/04/13/uninitialized-constant-actionmailer-quoting-encoding/feed/ 1
Jquery Full Calendar with RubyOnRails /2010/03/29/jquery-full-calendar-with-rails/ /2010/03/29/jquery-full-calendar-with-rails/#comments Mon, 29 Mar 2010 12:30:11 +0000 Akhil Bansal /?p=359
Cross Posted from http://vinsol.com/blog

Contrary to popular belief, working on a client project gives us a generous margin of creativity and explore innovative solutions.Take the example of a recent project I was working on. The client required a collaboration-based calendar module for their application similar to Google Calendar. Initially we started developing it from scratch , but then, we found an awesome Jquery plugin.

FullCalendar” provides a full-sized, drag & drop calendar. It uses AJAX to fetch events on-the-fly for each month. It also supports an intuitive interface to manage events that spans over multiple days or weeks. It is visually customizable and exposes hooks for user-triggered events (like clicking or dragging an event).

I decided to give it a try and utilize its hooks for user triggered events within our Rails application. This small effort resulted in a barebone Rails app that might provide a good base for your project which require calendar, scheduling or appointment features. I called it fullcalendar_rails and it is now available on github with a working demo at http://fullcalendar.vinsol.com.

Update: Added recurring events functionality to the demo app.

Feel free to give your valuable feedback. I hope you will find this useful.

/2010/03/29/jquery-full-calendar-with-rails/feed/ 5
11 Things to Consider Before Deploying Your Rails Application /2009/11/16/11-things-to-consider-before-deploying-your-rails-application/ /2009/11/16/11-things-to-consider-before-deploying-your-rails-application/#comments Mon, 16 Nov 2009 11:51:25 +0000 Akhil Bansal /?p=355
Cross Posted from http://vinsol.com/blog

At VinSol, we have been developing and deploying Rails applications for more than four years. During this period, we have identified some best practices that we prefer to follow while deploying rails application to production server.

Below is the checklist of these practices:


1. Ensure that NS records and MX records are changed if they need to be changed

Changing nameservers will point the domain to the hosting server, and changing MX records will redirect incoming mails to the mail server. As a very first step, we should make sure that name servers of the domain are set to be the correct one. Changing MX record is a must if our application is parsing incoming mails or we wants to use other mail services for e-mail exchange, for example Gmail.


2. Ensure some backup mechanism in place for both data as well as user uploaded content like images/documents etc.

Since production data is very critical, we must setup backup mechanism. It could be some type of scheduled task that takes periodic backup of all critical data, Or it could be some type of backup service provided by hosting company. When we talk about critical production data, it includes production DB, content generated by application users like images, documents, etc.


3. Ensure database indexes

We might have done development without having proper database indexes, but we should avoid going to production without them. Adding indexes might slow down insert queries a bit but it increases the performance of read queries. It applies when application in production has percentage of read operations much more than write operations.


4. Enable your slow query log

This is specific to MySQL. Enabling slow query log allows MySQL to log slow running queries to a file. And this log can be used to find queries that take a long time to execute and are therefore candidates for optimization.


5. Ensure exception capturing is in place

We might want to be notified when something bad happens to our application. There are several hosted services available who receive and track exceptions, for example Hoptoadapp.com, GetExceptional.com etc… Either we can choose one from these hosted services or we can use “exception notifier” plugin.


6. Ensure adding entries for cron/scheduled jobs

Most of the applications have some functionality/jobs that need to be run periodically, for example generating invoices, sending newsletters etc. In most cases these jobs are done by a rake task. We should make sure that we have added such jobs to cron or similar program.


7. Monitoring important processes

To ensure that our site is up 24×7 we need to ensure that all processes that our application needs are up. There can be many processes like MySQL, Mongrel, Apache etc.. These processes are very important as our application directly depends on them. For example if MySQL process get killed accidentally, our application would not be able to connect to MySQL and will start throwing exceptions.

We can choose any of the available monitoring tools like God, Monit, 24×7 etc…


8. Ensure confidential data filtering

We would never like to leak/share confidential information of our application users. We should make sure that none of the user’s confidential data like SSN, Credit card info, password are being written to log files. We might not have paid much attention on this while developing the application.


9. Rotate log files

Once our site is up and running, every single request write some text in log file. And hence size of the log file keeps on increasing. Larger log files can put us in trouble if we get it beyond certain size. Its difficult to manage these log files, as larger files need more memory to open and need more time to download. In one of the rescue project we did , the log file size was 3GB.

We would recommend having logrotate setup for the application.


10. Setup Asset Host

Setting up asset hosts can reduce loading time by 50% or more. We must setup asset hosts for our application. Once asset hosts are all set, our static files will be delivered via asset hosts for example asset1.hostname.com, asset2.hostname.com


11. Clearing up stale sessions

We should make sure we should not left any stale session on the server. If our application is using DB or file system as session store, we must add a schedule task to delete stale sessions.

These are some of the points we have identified from our past experience and we might be missing some. Feel free to always add them as comments, and I’ll keep this post updated.

Akhil is a senior software engineer working with Vinsol for last 5 years. He is an inhouse deployment ninja.



We also provide affordable rails deployment services.



/2009/11/16/11-things-to-consider-before-deploying-your-rails-application/feed/ 2
Displaying information about your git repository /2009/11/12/displaying-information-about-your-git-repository/ /2009/11/12/displaying-information-about-your-git-repository/#comments Thu, 12 Nov 2009 13:09:15 +0000 Akhil Bansal /?p=332 Want to see information about your git repository?

Based on a discussion here Duane Johnson wrote a very useful bash script. I am using this script from months and would like to share with you. You can download this script here(git-info.txt (667)).

You can also add an alias like below, so that I can be a accessed by a single command “gitinfo”

alias gitinfo="/home/akhil/git-info.txt"

When you run this script from your working copy it displays:

  • Remote URL
  • Remote Branches
  • Local Branches
  • Configuration (.git/config)
  • Most Recent Commit

Isn’t it useful, give it a try ;-)

/2009/11/12/displaying-information-about-your-git-repository/feed/ 1
Change timezone of ubuntu machine from command line /2009/07/15/change-timezone-of-ubuntu-machine-from-command-line/ /2009/07/15/change-timezone-of-ubuntu-machine-from-command-line/#comments Wed, 15 Jul 2009 15:47:51 +0000 Akhil Bansal /?p=303 If you guys want to change timezone of your ubuntu machine then you can do it by issuing:

dpkg-reconfigure tzdata

This may be helpful if you deal with servers.

/2009/07/15/change-timezone-of-ubuntu-machine-from-command-line/feed/ 14
Multiple versions of ruby on ubuntu /2009/06/23/multiple-versions-of-ruby-on-ubuntu/ /2009/06/23/multiple-versions-of-ruby-on-ubuntu/#comments Tue, 23 Jun 2009 15:33:26 +0000 Akhil Bansal /?p=300 Three-Four days ago I was in a situation where I need to have multiple versions of ruby and rubygems on my ubuntu machine. I was lucky, I found an awesome article http://blog.michaelgreenly.com/2008/08/multiple-versions-of-ruby-on-ubuntu-2.html. This really solved my problem, Many thanks to Michael Greenly.

/2009/06/23/multiple-versions-of-ruby-on-ubuntu/feed/ 1