Monday, November 16, 2009

Rails and Amazon Web Services

Hi all,

One of the Most wanted skills in Ruby on Rails right now is "Rails and Amazon: Libraries and Plugins for EC2, S3, SimpleDB, SQS, FPS and DevPay Integration". The below link will much useful those who are looking to learn about these integartions.

Rails become like a ocean now itself, just think after the official release of "Rails 3". That should be a cyclone on web development industries.

Think more about "Rails", do more development :)

Wednesday, October 21, 2009

Simple Array Comparison in Ruby

Here is a simple method to compare two arrays using Ruby, few examples:

> [1,2,3] <=> [1,2,3]
=> 0
> [1,2,3] <=> [2,2,3]
=> -1
> [1,2,3] <=> [3,2,3]
=> -1
> [1,2,3] <=> [1,3,3]
=> -1
> [1,2,3] <=> [1,1,3]
=> 1

By use of Terinary Operator (<=>), we can acheive the simple method to compare two arrays of comparison.

Hope this will help for someone or me in future!!!

Friday, July 3, 2009

Get Start/Switch your projects with Ruby On Rails

For this past few years i missed to read an wonderful article about the succession of Ruby on Rails. This article explains us "How Ruby on Rails succeeded and intention to Create this?" Dont ever miss any one to read this article. Just click the below link and start to work with Ruby on Rails.

For each and every programmers or technicians or business development managers, this article should read and need to get know about Ruby On Rails(ROR).

Especially in India, so much of them didnt even know about this framework and language. Some bigger companies are not yet started to accomodate this simple framework( rails ) with the base powerful language (ruby). They should come over and start to work on this technology. Its the only language now the direct competitor for Java in the whole world. In Denmark, it almost 90% of programmers using this framework.

It Benefits a lot. In Brief,

-> Reduce the number of hours to develop a application.
-> Reduce the number of developers involved to create a application.
-> Reduce the stress, energy to create the applications by the developers.
-> Easy to learn the framework.
-> More compatible with all platforms.
-> Easy to implement the Agile methods.

Finally, Last but not Least, its everthing "OPEN SOURCE". Get think over the above advantages and start / switch your projects with Ruby On Rails.

Happy coding and will see you in another information.

Saturday, June 13, 2009

Searching String(s) in file(s) using Ruby

Searching String(s) in file(s) using Ruby is very simiple. Here is the sample code to manipulate it.

# searching a string in a file
def print_line_containing(file, str){str}/).each do |line| puts "#{line}" end

# searching multiple strings in a file
def print_line_containing(file, str1, str2){str1}\s+#{str2}/).each do |line| puts "#{line}" end

# searching multiple strings in multiple files
def print_line_containing(file_array, str)
file_array.each do |file|{str1}\s+#{str2}/).each do |line| puts "#{line}" end

I hope this will help you all!

Wednesday, June 10, 2009

Building Shopping Cart with Ruby on Rails in few minutes

we can easily build a shopping cart application in a fraction of few minutes.

Use the above link and download the substruct application. Follow the instructions like installation, svn updating the substruct engine, and etc., from the left nav bar on that page.

Then you will get the shopping cart application with payment integration with the Active Merchant plugin.

Get use of open source and explore your thoughts with your application.

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

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 or on this.
Keep Updating your knowledge.

Friday, March 20, 2009

map method is one of the best methods in rails

This methods will turns the symbol to proc.

Here is an example:

>> tcs = TemplateCompatibility.find :all, :select => "DISTINCT id, template_id"
=> [#"1", "id"=>"1"}>, #"2", "id"=>"2"}>, #"3", "id"=>"3"}>, #"4", "id"=>"4"}>, #"5", "id"=>"5"}>, #"6", "id"=>"6"}>, #"7", "id"=>"7"}>, #"4", "id"=>"8"}>]

If you want to extract a specific field from the above result set or an array, here in the above example i want to extract specifically template_id values, then we can use "map" method to get the values in a new array. Here is the syntax to use it with this example.

=> [1, 2, 3, 4, 5, 6, 7, 4]

Enjoy Coding & hacking too!

Thursday, March 19, 2009

Difference Between rspec and rspec-rails gems/plugins

rspec gem or plugin => basic rspec without rails support (runner, rake
task, api for describe/it, should etc)

rspec-rails gem or plugin => extra support for rails model view and
controller, database integration, code generation (script/generate)

It doesn't matter whether you use the gem or the plugin. Just pick one
that suits your project.

Tuesday, March 17, 2009

Free E-Magzines for Rails

"The Rubyist" and "Rails Magazine" are the magazines has announced to download their issues as E-book/E-Magazine per month. You can download their issues from their official websites itself. That is,

Download and Enjoy :)

Keep on improve your skills and knowledge in Ruby On Rails.

Monday, February 16, 2009

creating a directory using ruby

Creates a directory and all its parent directories. For example,

FileUtils.mkdir_p '/usr/local/lib/ruby'

causes to make following directories, if it does not exist.

* /usr
* /usr/local
* /usr/local/lib
* /usr/local/lib/ruby

You can pass several directories at a time in a list.

Wednesday, February 4, 2009

submit_tag will be override the functionality reset in Rails.

Eg: Reset tag in Rails
<%= submit_tag "Reset", :name => 'reset', :type => 'reset', :id => 'task_reset' %>