Monday, September 20, 2010

Ride in ECR..

Today morning when i got up my bed and thought about the day I felt bored and thought of travelling somewhere around Chennai. As most of my friend have gone to their native places, I was not sure how the travel would be, a lonely drive is always tough in any case. But I felt there must be something interesting and decided to start by afternoon. Among the list of places around Chennai, I felt Mamallapuram through ECR should be the place to visit and read about various places around Mamallapuram before leaving home. By 2.30 pm I started from my home carrying a water bottle in my bag and a camera. While leaving my home itself I was very sure that the trip would be an interesting and joyful one as it was actually. Within 20 minutes I hit the ECR. The ride in sea breeze was awesome. It was very wonderful and I was very thrilled to enjoy the rest in my path. The traffic was bit worry till Mayajaal because of Vinayagar Chathurthi Oorvalam and after that I was able to drive bit freely hitting 80 Km/H. After crossing the city, I had a tender coconut and faced a board saying 39 KMs to reach Mamallapuram. After crossing Muttukkadu Boat house, I wanted enjoying the scenary than racing so was steadily riding in 50Km/H.

I was attracted by a solitary palm tree on the banks of back water lake. The path from road to that place was very dirty and tough but I decided to spend sometime there. It was really a nice place. On the other bank of the lake there was a resort and the view from my side was great. I tried capturing that but to my camera's eye it didnt look nice. Then welcomed by the hands of silver oaks on both sides of the road. I thought of spending sometime there but couldnt as they were all occupied by diffent groups of people all consuming liquor and all. So saying bad luck to me, I continued my ride and halted in a Tourism dept run Drive-Inn. I had some cool drinks and there was few stone benches for enjoying the sea breeze and an wonderful scenary of Oak trees and sea in the background. After riding sometime I was invited by the Welcome board of Tiger Caves. Wow! what a place it is! Green everywhere with huge rock caves here and there and some wonderful Rock sculptures attracting eyes. Among the rock sculptures, I found two are very cute and great skilled work. The first one is a Siva temple of a single rock. It was a huge rock carved skillfully to three rooms and in the middle there is a Lingam. There was a board saying to not take the photograph of that siva lingam. The next one is bit more interesting. A huge rock resembling a tiger in elevation but in the rear, it was carved have many tiger heads. The another most important thing about the place is you cant just leave the place without saying about sound of sea waves colliding the rocks. Unbelievable sight! Green everywhere but when i stepped in further, there was a beach. I spent time long time sitting in the green grass listening the waves. Now and then Minas were making sound and that all made me feel heaven. I found the tiger caves is not having a proper bus stop and hence there is not much croud..Infact no crowd was very good for me to enjoy the place. I left the place by 6 pm and reached Mamallapuram finally :) As it was getting darker I was not able enjoy the sculpures fully but made an oath to come back soon exclusively to Mamallapuram. I then sat in the beach for sometime eating lays, Masala Kaju and Sprite.
I finally left Mamallapuram beach by 7 and reached home by 9pm after having dinner in OMR Nallas Appakadai. It was really wonderful. I never felt tired of riding bike for the total of 118 Kms up and down. It was full of enjoyment. It is really a very happy and unforgettable trip than I assumed how it would be at the beginning of the trip. Oh now only I am feeling pain in my palm and fingers. Some poto shots are here

Sunday, September 05, 2010

InPlaceEditor handling ActiveRecord validations in Rails

Last week I was facing an issue with Ajax InPlaceEditor in my Ruby On Rails application. The editor is very simple and when a page item is updated, the corresponding table is updated and the new value is updated on rendering. In my application i need to provide the user, an option to update his email id. Part of my controller

if @user.update_attributes(params[:name] => params[:value])
render :text => CGI::escapeHTML(@user.send(params[:name]).to_s)

It updates the database and renders the latest updated value if the active record validations are satisfied and the table is updated. I was worried about the else part i.e if the validations are failed, i should not update the table and the error message should be displayed with the original value retained in the page. So in this case i need to update two values, the original field value should be retained and the error value should be updated. In my controller i was having,

else
err_message = first_error(@user.errors)
render :update do |page|
page.replace_html params[:field_id].to_s, prev_value
page['notification_message'].hide
page.replace_html 'notification_message', :partial => 'shared/error', :object => err_message

I was shocked seeing some my field got updated with some chunk jvascript. I read InPlaceEditor docs and found that the field will get updated with the value returned from the controller. So in my case it takes my second page.replace_html as the returned value and updated the field. I googled and found many are having this issue but no one has mentioned any solution for this. Then I found that the script.aculo.us Ajax.InPlaceEditor is only designed to update one page field--the one that was edited. After going through the code, I realized what was happening was that both of my replace_html calls were actually working, but as part of what Ajax.InPlaceEditor does it returns the final value of the render call, and sticks it into the field that was edited. This is just the default behavior, as it assumes you only want to update that one field.

Looking into the Ajax.InPlaceEditor code,(relevant lines in bold):

handleFormSubmission: function(e) {
var form = this._form;
var value = $F(this._controls.editor);
this.prepareSubmission();
var params = this.options.callback(form, value) || '';
if (Object.isString(params))
params = params.toQueryParams();
params.editorId = this.element.id;
if (this.options.htmlResponse) {
var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
Object.extend(options, {
parameters: params,
onComplete: this._boundWrapperHandler,
onFailure: this._boundFailureHandler
});
new Ajax.Updater({ success: this.element }, this.url, options);
} else {
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
Object.extend(options, {
parameters: params,
onComplete: this._boundWrapperHandler,
onFailure: this._boundFailureHandler
});
new Ajax.Request(this.url, options);
}
if (e) Event.stop(e);
}

What was happening was that it was creating a new Ajax.Updater, which is meant to update a single element with the return value from the url it calls, which turned out to be that chunk of Javascript above when I used the render :update block. The Javascript was being eval'd correctly, and updating both my fields, but then Ajax.Updater was re-updating the 1st field with the result of the render block, which was that chunk of Javascript.
So both of my replace_html in render update are actually working and the problem is only with the editors updater. So I called a new request to reload after that updater. so my modified script looks like

if (this.options.htmlResponse) {
var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
Object.extend(options, {
parameters: params,
onComplete: this._boundWrapperHandler,
onFailure: this._boundFailureHandler
});
new Ajax.Updater({ success: this.element }, this.url, options);
new Ajax.Request(this.url, options);
} else {
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
Object.extend(options, {

Now everything works great:) Hope this will be useful if you are facing similar problem with InPlaceEditor

Saturday, September 04, 2010

வேணுமடி நீ எனக்கு..!!!

Recently i read a mail titled "நீ எனக்கு வேண்டாமடி". It was a nice poem saying why the guy should sacrifice his love for his family. Its link. I liked the way the poem was written but not the meaning of it. So thought of writing why the guy should not leave his love...given here few lines of that

வேணுமடி நீ எனக்கு..!!!

எனக்கு வேண்டியதை
நான் வேண்டுமுன்னே
பார்த்துப்பார்த்து செய்தஎன்
தாய்த் தந்தைக்கு இன்று
வேண்டும் ஒரு மகள்..
அதற்க்கு வேணுமடி நீ எனக்கு...

என்சிறு செயலையும் விண்ணுக்கு
உயர்த்திப் பேசிய சகோதரிகள்
ஒரு நாளாயினும் உண்மையாய்
மகிழ்ந்து பேச வேண்டும்..
அதற்க்கு வேணுமடி நீ எனக்கு...

நான் செய்யும் எதுவும்
சிறக்க வேண்டும் தோழிக்கு
என்றும் என்நட்பு
சிறக்க வேண்டும்..
அதற்க்கு வேணுமடி நீ எனக்கு...

நான் வாழ்க்கையை ஒருநாளேனும்
வாழ வேண்டும்..
அதற்க்கு வேணுமடி நீ எனக்கு...!!!