Friday, May 22, 2009

Array Mapping in Ruby

Hi to All,

Here is the sample code to know the usage of array mapping in Ruby.

>> User.find_all_by_office_id(20)
=> [#, #]

If you want to map only the User id's from the above result set. then you should use like this:

>> User.find_all_by_office_id(20).map(&:id)
=> [1032, 3646]

If you want to use these User id's in an another query with "IN" predicate. Then you should use like this:

>> User.find_all_by_office_id(20).map(&:id).compact.join(",")
=> "1032,3646"

the compact will you delete the blank array element from the result set.

then it joins with "," (comma). So finally you will get the string with concatenated id's with comma. You can use this string in the another query with "IN" predicate, like this

>>user_ids = User.find_all_by_office_id(20).map(&:id).compact.join(",")

>>y Website.find(:all, :conditions => "user_id in(#{user_ids})")

you will the websites list for these users.

Friday, April 17, 2009

Rails 2.3.2 bugs with solutions

For the rails thinkers this link may helpful a lot to solve their basic issues with recent rails released version 2.3.2


http://tiny.cc/67kLX

Gem Capistrano issue on Ruby on Rails

If you are going to use capistrano gem for deployment.

you should install two gems for this:

sudo gem install capistrano
sudo gem install capistrano-ext

If you missed out "capistrano-ext" gem to install,

it wont you to execute capistrano operations like deploy, log, etc., i.e tasks which are using your deploy.rb

/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- capistrano/ext/multistage (LoadError)

and it returns the above error.

Wednesday, April 15, 2009

Rmagick and ImageMagick Installation steps in Ubuntu

Hi to all,

After 1 to 2 hours struggling with the Rmagick and ImageMagick Installation in Ubuntu 8.10, i have found a simpler steps to do:

1) Install "imagemagick" through apt-get or synaptic manager.
2) Again Install "libmagick9-dev" through apt-get or synaptic manager.
3) Then, sudo gem install rmagick ( recent version will get install )

If you want a specific version of rmagick, then use this
sudo gem install rmagick -v 1.15.12

Note: rmagick 1.15.12 version is a stable gem.

Tuesday, April 14, 2009

To install rubygems in Ubuntu

I prefer these commands to install updated RubyGems in Ubuntu. Use the below commands on your terminal and get it quicker.

sudo gem install rubygems-update
sudo update_rubygems

Thursday, March 26, 2009

Rails on Git

Git is one of the extreme repository storage media. Its similar kind of Subversion(SVN), CVS, Mercurial, etc revisioning system. Its pretty much useful for rails kind of frameworks. Even our Rails gem also switched to Git repository from SVN.

I feel more happy to work with it. Its fast and furious. i'll suggest you to adopt into this technology.

Today i have found one superb tool to find the difference and merging the conflicted file by comparing between the local and remote files with Good GUI.

man page for git mergetool

meld is one of the tool to find the difference between multiple files. Use the below command to run the tool.

git mergetool -tool=meld


Sample Dispaly for this tool:



I will update about GIT regularly on either gokulamurthy.blogspot.com or on this.
Keep Updating your knowledge.