Archive for the Ruby On Rails Category

Ruby Time object issues

Posted in Ruby On Rails on April 6, 2009 by Asanga Bandara Wijekoon

I faced this problem when I try to deduct database stored time objects. My self and I think most of developers use time object to store time. But time objedct create and store with an aditional information like year, month and time, etc.

So when we try to decduct two time objects it just not give us only the time difference as what we belive. It calculate the difference of both time object not only considering the time but also with considering year, month and day difference.

So be aware about that when u are calculating the time difference and I mention some methods to overcome that issue in below.

(time_object_2) – (time_object_1)%86400

this will give only the time difference. Other than that u can cast all the time object to a current time object year, month and day by using

today=Time.now #today time object

time_object # which is the time object we neet to cast for certain year month and day

cast_time_object=Time.mktime(today.year,today.month,today.day, time_object.hour, time_object.min, time_object.sec,0)

code. Now we can deduct time objects and we can calculate correct time different.


How to access rails inner hash with in a hash

Posted in Ruby On Rails on April 6, 2009 by Asanga Bandara Wijekoon

Most of the time u are posting u’r post with hash with include another hash. As an example I copy a post parameters I have posted.

Parameters: {“commit”=>”Create”, “date”=>{“minute”=>”30″, “hour”=>”19″}}

I copped this from mongrel  server console.  So how access the :minute value?

Ruby give us a way for accessing inner hash with another hash. So we can access this using following method

params [:date][:minute]

Rails automatically assign post parameter to the “params” hash. Here params is the first hash and we access the date hash with in it. Then we access it’s minute key and get the value.

Rails Ajax and tr issues

Posted in Ruby On Rails on April 6, 2009 by Asanga Bandara Wijekoon

I think this post may help for rails new users. First I will mention how I faced the problem.

I used pure html and prototype functions with in a <tr> tag.

code is

<img src=”/images/delete_img.png” onclick=”new Ajax.Updater(’show_time_table’,'/showtimes/<%=showtime.id%>/’, {method:’delete’})”/>
I used this with in a <tr> tag and I don’t mention about the <td>. Here ajax call not execute until I put this code inside a <td> tag.

Ruby On Rails – Raisl 2.2.2 with mysql

Posted in Ruby On Rails on October 7, 2008 by Asanga Bandara Wijekoon

I have faced lot of difficulties in my ROR programming experiences and I think the way I answer those problem may useful for others also. So today onwards I will publish some useful posts for ROR developers.

Raisl 2.2.2 with mysql

Currently I am using windows xp machine with ROR 2.2.2. New Rails version doesn’t come with mysql gem. So we have to manually install it. If u are working in a secure network most of the time u may have to give proxy address for installing plugin or gems. We can give it as

set http_proxy=http://<your proxy address>:<port>

command. After u gave it then u can install mysql gem by just firing the command

gem install mysql

When u installing this gem u may face some problem with documentation. But make sure for proper usage at least u should install the gem. Then u can restart u’r server.

Ops, Now it says there is a missing libmysql.dll file. So download it and then copy it to windows/system folder.

Ok then u can again restart u’r server and now all works fine.

Go ahead and feel rails coolest features.