Friday, March 21, 2008

How to debug code in Rails 2.0.2?

The newbies of rails 2.0.2 developers may get headache because some changing are not known. Even here there is a change in the way to debug code in Rails 2.0.2.

In Rails 1.2.3, you place breakpoint command in the code then run another command ruby script\breakpointer in command dos console. At last you can debug your code by viewing some variables, changing the value, and testing what wrong with that. But, there is one limitation that you can use only instance variables, local variables could not be retrieved.

In Rails 2.0.2, these don't exist anymore. In order to debug your code, you need to install another gem by running gem install ruby-debug. Then, place debugger instead of breakpoint because this command was renamed. The script breakpointer that used to be in the folder script of your rails application now don't exist anymore. Next, you need to end your web server and then start with additional option ruby script\server --debugger. If you want to end current debugging, type cont. If you type exit, your web server will end immediately. There is one thing fixed, you can local variables in the debug mode.

Monday, March 17, 2008

How to compress image file in RMagick

Normally, you compress the image file by setting quality of image object to less than 100 percent.

img.write("myimage.jpg") { self.quality = 50 }

However, this usually not always works because suppose you have one big jpeg file (3000x1000) and you want to crop it into 250x250 dimension per each. Therefore, all of your crop files added up together should be less than the original file size. Somehow, this won't be true because the original file contains image profile so when you crop it all of crop files also contain this image profile. This is a problem that your crop files added up together are bigger than the original file. The solution of this I found in http://thinkingrails.blogspot.com/2007/07/compression-in-rmagick.html to remove image profile. Using either image.profile!("*", nil), delete_profile("*"), or image.strip! to remove all of these meta data because we don't need them in thumbnail image. Thanks to Arunkumar.

Tuesday, March 11, 2008

Uploading file asynchronously using ajax-like-technology

My boss asked to me to modify my popup container to allow the user uploading the file. I use ajax to submit data to the server. The response from the server I use a json format indicating a success or failure, validation errors, required login, .... Now, this won't work any more because XMLHTTPRequest object cannot handle file upload. To upload the file to the server asynchronously just like GMail and Yahoo Mail, you need to create an iframe and the set the target attribute of that form element to that new iframe. Then, on the onload event of that iframe, you can know that response from the server is completed or not. I have found another link related to this issue that quite fit to my need, but the server code of this technique is PHP. http://www.devbox.info/upload-files-asynchronously-using-ajax-like-technology
Anyway, I have modified a little bit to make it fit to my needs. One of the pitfalls is that it creates an iframe every time the user submit the form, but this doesn't matter you can modify by yourself. At last, I want to say thanks to the author of that page.

How to run a cron job with acts_as_taggable?

Recently, I get an error with the acts_as_taggable when my hosting server upgrades Rails to 2.0. It cannot find that gem on the environment.rb file. Normally, we write: require_gem 'acts_as_taggable'. The solution is to change from that code to require 'taggable'.


Then, I got another problem because my cron job is not working anymore. I try to fix this about a few hours and find the solution, but I don't know it is a wise solution for that or not. I open a file called 'runner' inside the script folder inside my rails application and then change one line from:
require File.dirname(__FILE__) + '/../config/boot'
to:
require File.dirname(__FILE__) + '/../config/enviornment'

Saturday, March 1, 2008

BUG: Error message when you visit a Web page or interact with a Web application in Internet Explorer: "Operation aborted"

My friend just faced this problem recently. He develops a page. It works very well on FF, but when it opens on IE6. The internal error message from IE said that "Operation aborted". Now it is fixed due to the solution/workaround in this http://support.microsoft.com/kb/927917/en-us.

This is a bug in IE 6 that has been reviewed lastly on October 27, 2007. The problem is that a child container HTML element contains script code that tries to modify the parent container element of the child container. The script code tries to modify the parent container element by using either the innerHTML method or the appendChild method.

<html>
<body>
<div>
<script type="text/Javascript">
document.body.innerHTML+="sample text";
</script>
</div>
</body>
</html>


Workaround: To work around this problem, write script blocks that only modify closed containers or that only modify the script's immediate container element. To do this, you can use a placeholder to close the target container, or you can move the script block into the container that you want to modify.

For more information, go to http://support.microsoft.com/kb/927917/en-us

Subscribe in a Reader