Posts

Rails - Calendar date select in 3 simple steps

1. Install plugin script/plugin install http://calendardateselect.googlecode.com/svn/tags/calendar_date_select 2. Include JS & CSS to your layout file     <link href="/stylesheets/calendar_date_select/blue.css" media="screen" rel="stylesheet" type="text/css" />     <script src="/javascripts/calendar_date_select/calendar_date_select.js" type="text/javascript"></script> 3. Calendar date select tag <input type="text" name="user[date_of_birth]" size="30" autocomplete="off" onselect="new CalendarDateSelect( this, {year_range:50} );" onclick="new CalendarDateSelect( this, {year_range:50} );" value="<%= Date.today %>"/> Restart the server as the plugin has been installed! Calendar date select works! Notes : 1. If you wish to turn on the time, use this => new CalendarDateSelect( this, {year_range:50, time:true...

RubyConfIndia - May 28, 29 - 2011

Image
Team Kaverisoft 

Rails 3 - rake aborted! undefined method `task' for #

Hi, In Rails 3. there was a problem with rake 0.9.0 gemset. When i do rake db:create I got the following error, undefined method `task' for # The fix is as follows, go to config/application.rb file. Add this line inside the class, include Rake::DSL That fixed the problem

Helper method to display number in money format - number_with_delimiter

Image
Examples number_with_delimiter(12345678) # => 12,345,678 number_with_delimiter(12345678.05) # => 12,345,678.05 number_with_delimiter(12345678, :delimiter => ".") # => 12.345.678 number_with_delimiter(12345678, :separator => ",") # => 12,345,678 number_with_delimiter(12345678.05, :locale => :fr) # => 12 345 678,05 number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",") Source : http://apidock.com/rails/ActionView/Helpers/NumberHelper/number_with_delimiter Learn : Agile Web Development with Rails | Beginning Rails 3

Will Paginate - Array Pagination

Image
Wanna paginate an Array using will paginate.. Here is how i did.. Add this as method, Array.class_eval do def paginate(page=1, per_page=15) pagination_array = WillPaginate::Collection.new(page, per_page, self.size) start_index = pagination_array.offset end_index = start_index + (per_page - 1) array_to_concat = self[start_index..end_index] array_to_concat.nil? ? [] : pagination_array.concat(array_to_concat) end end And with the array @results do @results.paginate reference: http://www.devchix.com/2007/07/23/will_paginate-array/ Regards, Srikanth Learn to Program with Ruby | Ruby Pocket Reference

Ruby Sorting Manually by created at

Image
Hi, I have used this for sorting manually. @results.sort{|x, y| x.send(:created_at) y.send(:created_at)} P.S. @results is an array tht has many records. Concepts and Code

Rails + Google Map V3 with Marker, Bounds

Hi I have used this function to load Google map with Marker and bounds. function initialize(lat, lon, div_id) { var myLatlng = new google.maps.LatLng(lat, lon); var myOptions = { zoom: 8, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var bounds = new google.maps.LatLngBounds (); var map = new google.maps.Map(document.getElementById(div_id), myOptions); var trucklatlng = new google.maps.LatLng(lat,lon); var marker = new google.maps.Marker({ position: trucklatlng, map: map, title:"Assist" }); var LatLngListFake1 = new google.maps.LatLng(lat + 0.005 , lon + 0.005); var LatLngListFake2 = new google.maps.LatLng(lat - 0.005, lon - 0.005); bounds.extend(LatLngListFake1); bounds.extend(LatLngListFake2); map.fitBounds (bounds); } In the View File: Just call, <script>initialize(lat, lon, div_id)</script>