When I run locate test.rb on ubuntu 12.04 from /home/user/ruby, It display all the files in system ending with test.rb except test.rb in /home/user/ruby.

From http://www.linfo.org/locate.html I read that locate command only returns files for which user has access permission, I created this file I have full permission then why locate is not displaying it's path.
You need to read the documentation to the end, update the locate db is necessary:
sudo updatedb
From the documentation that you have linked:
Because the database is not updated immediately, recently created files and directories might not show up when searching for them with locate or slocate. Fortunately, however, it is a simple matter to update the database manually, although it might take a few minutes. Manual updating can be accomplished by logging in as the root user (i.e., administrative user), such as by using the su (i.e., substitute user) command, and then issuing the following command:
updatedb
In fact locate uses a database which is usually periodically updated and which is system-wide. This database can be updated manually by running, with adequate permissions, the command updatedb - as the man page for locate says: "locate can never report files created after the most recent update of the relevant database."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With