IE7 Issues – supporting IE7 in modern web apps

Ok – so you need to support IE7. Here’s a short list of things you may need

needsIEFix:function() {
var ua = navigator.userAgent;
return /msie [5-7]\./i.test(ua);

Expected identifier, string or number
  • Things that were center aligned in IE8 and chrome, firefox etc were broken in IE7. Used this to fix this prob (
  • z-index problem. Google this and you will see many solutions. My main prob was my dropdown menus were being hidden below other divs. I applied the following javascript soln.

if( common.needsIEFix() ) {
var zIndexNumber = 1000;
$(‘div’).each(function() {
$(this).css(‘zIndex’, zIndexNumber);
zIndexNumber -= 1;

  • The above soln to z-index was causing some elements to disappear in IE7. The orig soln was zIndexNumber -= 10; which I replaced with zIndexNumber -= 1; as the zIndex was becoming negative and hence some elements were disappearing.
  • Then came the prob of JQuery dialogs which would not allow keyboard inputs i.e forms in modal dialogs were not fillable – no keyboard events were reaching it. The soln was to make the modal dialogs non modal as in IE7 modal dialogs do not allow keyboard inputs to be received by the dialog.
  • Jquery .html() function to replace html of a given div was not working e.x $(“#xyz”).html(custom_html) was not working. the problem was that #xyz was not unique id in the current DOM. Ensure unique id is used when using .html() function.

Securing logged_exceptions pages

We use the exception_logger gem ( for capturing exceptions, cancan ( for authorization and devise ( for authentication.


So how do you secure your logged_exceptions page ?

1. In your production.rb add the following lines


   config.after_initialize do
    LoggedExceptionsController.class_eval do
      # include authentication and authorization before access 
      before_filter :authenticate_user!
      self.application_name = "Jqt"

2. Ensure your ability filed has the following entry for the role that can manage logged_exceptions 
  can [:manage], LoggedException

3.  Restart your server

www, verisign and rack rewrite

So I got the SSL certificate for – guess what ? it does not work for Now what – fork out more for a cert ?

Thats where rack-rewrite comes in and this post helped.

There is a minor error in the post mentioned above in that “:if =>" should be replaced by ":if=>"



Sanitize paperclip filenames

If you are using paperclip and you upload a file containing spaces in the filename (ex windows users)  –  this can cause probs if your server is a unix box. Hence we would like to sanitize the filename of every attachment  – across all models that use paperclip

1. Create a file called paperclip_config.rb in config/initializers

2. Add the following lines to it


# Use the escaped_filename for all attachments
  :path => ":rails_root/public/:attachment/:id/:style/:escaped_filename",
  :url =>  "/:attachment/:id/:style/:escaped_filename")

# ensure that escaped_filename for all attachments is actually escaped 
Paperclip.interpolates('escaped_filename') do |attachment, style|

  s = basename(attachment, style) 
  # Remove apostrophes so isn't changes to isnt
  s.gsub!(/'/, '')

  # Replace any non-letter or non-number character with a space
  s.gsub!(/[^A-Za-z0-9]+/, ' ')

  # Remove spaces from beginning and end of string

  # Replace groups of spaces with single hyphen
  s.gsub!(/\ +/, '-')
  return s + "." + extension(attachment, style)

Rack SSL

Finally got SSL working for our app

1. Generate a self signed cert and attached to our instance on EY
2. Added the following to Gemfile

gem ‘rack-ssl-enforcer’, ‘0.2.2’

3. Added the following to config/application.rb

# :strict=>false ensures everything else is forced to http
# :force_secure_cookies => false ensures cookies can be shared between secure sign_in and http based other pages
config.middleware.use Rack::SslEnforcer, :only => [/sign_up/, /sign_in/, /\/credits/], :force_secure_cookies => false, :strict => true


Voila – app now uses SSL for the really important URLs

ActiveRecord Error Methods

Some methods are provided to allow you to add validation errors to the collection
manually and alter the state of the Errors hash.

errors[:base] = msg
Adds an error message related to the overall object state itself and not the value of any
particular attribute. Make your error messages complete sentences, because Rails does
not do any additional processing of them to make them readable.

errors[:attribute] = msg
Adds an error message related to a particular attribute. The message should be a sentence
fragment that reads naturally when prepended with the capitalized name of the attribute.

As you might expect, the clear method clears the Errors collection.

Things I did’nt know about AR

  • User.where(:email => nil)
  • User Load (15.2ms) SELECT * FROM users WHERE ( IS NULL)
  • The hash notation is smart enough to create an IN clause if you associate an array of values with a particular key.
  • Product.where(:sku => [9400,9500,9900])
  • Message.where(“subject LIKE :foo OR body LIKE :foo”, :foo => ‘%woah%’)
  • In other words, when you’re using named placeholders (versus question mark characters) you can use the same bind variable more than once. Like, whoa!
  • A clever, performant, and portable way to get a random record is to generate a random offset in Ruby.
  • Timsheet.limit(1).offset(rand(Timesheet.count)).first

git clone over http vs git

Ran into a problem while cloning git repo over http. The git clone http://xxx was always returning stale files.

Apparently you must run

$ git update-server-info

every time you commit into the repo so that http users can get the latest files.

For more info


Engine Yard : Logging into an instance

And how I struggled for this simple task. This is just in case you are new to this stuff

1. Get puttygen from

2. Generate a private/public key using puttygen and save to C:\Users\home\.ssh

3. Copy the public key to I mean the actual public key string not the file

4. Launch your application from EY but ensure your environment setup has  the key from step 3

5. Launch your instance and wait till the ssh link appears on your dashboard

6. Copy the ssh link

7. Open up putty and paste into Session->hostname the copied URL (ensure leading ssh:// is deleted from the copied URL)

8. Under connections->ssh-Auth clikc the Browse button and select your private key file from step 2

9.  hit the open btn to log into your EC2 instance





Hash and OrderedHash

Ran into a funny prob today which was resolved by using OrderedHash instead of Hash.  In ruby 1.8.x Hash is not an OrderedHash but in 1.9 even an ordinary Hash is Ordered. My dev was on ruby 1.9 but dreamhost is on 1.8.7 hence the problems.