Array of years using range((yr=Date.current.year)-9..yr).to_a#=> [2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010]Array of years using lambda Array.new(10){|i| Date.current.year-i}#=> [2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001]Array of monthsDate::MONTHNAMES.compact#=> ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]Array of abbreviated monthsDate::MONTHNAMES.compact.collect{|m| m[0..2]}#=> ["Jan", "Feb", "Mar", "Apr", "May", "Jun", … Continue reading Best ways to populate dynamic array of numbers in ruby
Author: sandipransing
Rails 3 Beautiful Code
Check out this SlideShare Presentation: Rails 3 Beautiful Codehttp://static.slidesharecdn.com/swf/ssplayer2.swf?doc=beautifulcodeinrails3-greggpollack-100218130149-phpapp02&stripped_title=rails-3-beautiful-code-3219240View more presentations from GreggPollack.
Zipcode validation using geokit in rails
1.Install geokit gemgem install geokitOR # Add following line inside rails initialize blockRails::Initializer.run do |config| config.gem 'geokit'endAnd then run commandrake gems:install2. Consider User model with zipcode as attribute fieldinclude Geokit::Geocoders class User :zipcode private def request_zipcode_validation_using_geokit # Method request google api for location # if location found then zipcode is valid otherwise # add validation … Continue reading Zipcode validation using geokit in rails
