Tuesday, September 28, 2010

Rails respond_to and IE File Download Security Warning

As discussed in my earlier post, I am working on a WEB API integration project involving Radiant. This is a public facing website and requires full support of Internet Explorer. So far, IE has proved to be a great pain. I have got an IFRAME rendering pages from another web application. Now, this application had a controller code with respond_to block.

def method_name
#some RUBY code
respond_to do |format|
format.js {#render some JSON}
format.html {#redirect to somewhere}

Now, everything seemed to be working good on FireFox and Chrome. Next was the turn of IE. As expected, MORE PROBLEMS.....!! It didn't work!!! It started showing File Download Security Warning Dialog. I had no clue what it was doing. I was totally stumped. Finally, after a bit of googling I came across this post. It saved my day.

As mentioned in the post, I tried printing the request.format for normal HTML request. To my surprise, IE was registering the Mime::Type to be "image/gif". Also, format.html? was nil.

I tried accessing the same action from FireFox. This time, the request format was set correctly to be "text/html".

Now, there is no Mime::Type registered for "image/gif". Hence, first accept type was taking preference. The solution (moving format.html before format.js) mentioned in the post worked for me.

Wednesday, August 11, 2010

undefined method `rewrite' for <#String: URL_STRING>

Currently, I am working on a WEB API integration project for a leading tourism company in Australia. I am using RADIANT, MySQL, Ruby 1.8.7 and Rails 2.3.8. While working on an issue, I ran into a weird error: undefined method `rewrite' for <#String URL_STRING>.

I was defining an instance variable @url in the controller. Also, I was using a simple form_for tag in the view.


class SomeController < ApplicationController
def some_method
#some logic


- form_for :some_object, :url => @url do |f|
- #some form fields
= submit_tag 'submit'

Everything seemed normal. But, I started getting this weird error. After a bit of search, I came to know that link_to, url_for and similar method uses ActionController::Base @url instance variable to generate URLs. So, make sure that you don't use/define @url anywhere in your controllers/helpers.

Monday, July 26, 2010

Commands...I always forget

  • Locating a file: sudo find / -name my-large.cnf -print
  • Disk usage: df -kh