Thursday, 13 December 2007

Display DateTime in client side Time zone


suppose you want to convert datetime in client side(browser) time zone and display it.
example take events, Events have date so that event date first you have to store it in database as GMT timezone
then write javascript function for onload event like this
function events()
{
var currentDate = new Date();
var offset = currentDate.getTimezoneOffset().toString();
new Ajax.Updater(‘events’, ‘/events/load_events?offset=’ + offset, {asynchronous:true, evalScripts:true}); return false;
}
The events.rhtml will be like this
<h1>Events</h1>
<div id=”events”></div>
In third line of javascript I am making an ajax call with updating “events” div tag.
This ajax will call the action “load_events” in controller “events”
events_controller.rb
def load_events
@events = Event.find(:all)
@offset = params[:offset].to_i
end
In view “load_evevnts.rhtml” calculate date with offset
<ul>
<% @events.each do |e| %>
<li><%= e.name %> on <%= (e.date – offset) %></li>
<% end %>
</ul>

Wednesday, 12 December 2007

Formating date Time in Rails


You can format Date field by using strftime function
example :
Time.now()
=> Wed Dec 12 15:48:59 +0530 2007
Time.now().strftime("%d/%m/%y %H:%M")
=> "12/12/07 15:50"
Here's the (shortened) table for strftime.
%a  weekday name.
%A  weekday name (full).
%b  month name.
%B  month name (full).
%c  date and time (locale)
%d  day of month [01,31].
%H  hour [00,23].
%I  hour [01,12].
%j  day of year [001,366].
%m  month [01,12].
%M  minute [00,59].
%p  AM or PM
%S  Second [00,61]
%U  week of year (Sunday)[00,53].
w  weekday [0(Sunday),6].
W  week of year (Monday)[00,53].
x  date (locale).
%X  time (locale).
%y  year [00,99].
%Y  year [2000].
%Z  timezone name.

Wednesday, 14 November 2007

HTML – Move to location(lable) in same page


suppose u have html page like this
<html>
<body>
<p>Name : Anand m Muranal</p>
<p>city : bangalore</p>
<p>state: karnataka</p>
<p>country : india</p>
</body>
</html>
now you want to some link which will go to city
then add some id to <p> tag of city and same id use for link, like this
<html>
<body>
<p>Name : Anand m Muranal</p>
<p id = “city”>city : bangalore</p>
<p>state: karnataka</p>
<p>country : india</p>
<a href=”#city”>Go to City</a>
</body>
</html>

HTML – Move to location(lable) in same page


suppose u have html page like this
<html>
<body>
<p>Name : Anand m Muranal</p>
<p>city : bangalore</p>
<p>state: karnataka</p>
<p>country : india</p>
</body>
</html>
now you want to some link which will go to city
then add some id to <p> tag of city and same id use for link, like this
<html>
<body>
<p>Name : Anand m Muranal</p>
<p id = “city”>city : bangalore</p>
<p>state: karnataka</p>
<p>country : india</p>
<a href=”#city”>Go to City</a>
</body>
</html>

Thursday, 23 August 2007

Multiple Database Connection in rails


Step1> Open your database.yml file. Under the three standard databases (development, test and production) add the informations needed to connect to you extra dataabse(consider u are running application in production mode and have student_database and second database has mail_database) . Use the standard yml sintax like:
development:
adapter: mysql
database: Login_app_development
username: root
password:
host: localhost
test:
adapter: mysql
database: Login_app_test
username: root
password:
host: localhost
production:
adapter: mysql
database: student_database
username: root
password:
host: localhost
mail:
adapter: mysql
database: mail_database
username: root
password:
host: localhost
Step2> I am considering that you have model for student database (ex: student) Create model for mail database using command prompt
ruby script/generate model mail
Step3> You need to manually overwrite the estabilish_connection method for the models linked to the external database(mail_database). Doing this execute these lines where u want to switch database to mail_database
dbconn = YAML.load(File.join(RAILS_ROOT, “config/database.yml”),”r”))["mail"]
Mail.establish_connection(dbconn)
After executing these lines all model will connect to mail_database if u want to shift back to student_database then execute these lines
dbconn = YAML.load(File.join(RAILS_ROOT, “config/database.yml”),”r”))[ENV['RAILS_ENV']]
Student.establish_connection(dbconn)
Using before_filter you can switch databases by executing above lines

Saturday, 5 May 2007

Munnar Kerala

Munnar: The Majestic Hills of South India

Nestled at an elevation of 5000 to 8000 feet above sea level, Munnar is a breathtaking hill station located at the confluence of three serene mountain streams: Mudrapuzha, Nallathani, and Kundala. This scenic destination, with its lush landscapes and tranquil atmosphere, offers a perfect escape from the hustle and bustle of daily life.

Breathtaking Views and Natural Beauty

Munnar is home to Anamudi, the highest peak in South India, standing tall at an impressive height of 2695 meters. The peak is an excellent spot for trekking, providing panoramic views of the surrounding hills and valleys. The high ranges of Munnar were once known as Kannan Devan Hills, named after a local landowner, Kannan Devan, who once resided in the Anchanad Valley.

Flora and Fauna

The region’s rich natural beauty is complemented by a diverse range of flora and fauna. Tea and coffee are the primary crops grown here, with sprawling plantations that stretch across the hills. Munnar is also famous for its Neelakurinji flower, which blooms once every twelve years, painting the hills in a mesmerizing blue hue. This rare spectacle attracts visitors from across the globe, making Munnar a unique destination for nature lovers.

Why Visit Munnar?

  • Anamudi Peak: Ideal for trekking and enjoying panoramic views.
  • Tea Gardens: Explore lush tea plantations and learn about tea processing.
  • Neelakurinji Blooms: Witness the magical blue transformation of the hills (when in season).
  • Serene Environment: Munnar’s cool climate, peaceful streams, and rich landscapes make it the perfect place for relaxation and rejuvenation.

Best Time to Visit:

The best time to visit Munnar is between September and March, when the weather is pleasant, and the lush greenery is at its peak.

Munnar’s enchanting beauty, its rolling hills, tea estates, and the rare Neelakurinji blooms make it one of the most sought-after hill stations in India. Whether you’re an adventure enthusiast, nature lover, or someone in search of tranquility, Munnar has something special to offer everyone.