Archive | Ruby

26 June 2010 ~ 0 Comments

Simple Search Rails plugin

SimpleSearch brings simple search to ActiveRecord. It ads simple_search named scope that accepts query as parameter. The idea is that you provide the query and plugin does the rest (splits query to keywords and compose where statement). This can be very useful in case you just want to filter list of records by some query, [...]

Continue Reading

04 January 2010 ~ 0 Comments

Ruby library for parsing, validating and formatting phone numbers

Tomislav Car has just released Phone, Ruby library for phone number parsing, validation and formatting. It should save you a lot of time if you need any of the following: * you have area where users input phone numbers in many different formats * output phone numbers in specific format * you need to send [...]

Continue Reading

19 September 2009 ~ 0 Comments

Radiant CMS, disable caching in development

I am working on extension for Radiant CMS. I wanted to disable caching for development, but wasn’t able to find right method for this, so finally I did it by putting this into my extensions activate method if RAILS_ENV==”development” Page.class_eval { def cache? false end } end This is more of a hack then a [...]

Continue Reading

22 August 2007 ~ 0 Comments

Determining the number of days in a month

Here is a simple method that returns number of days for wanted month and year. If year is ommited current year is selected. def month_days(month, year=Date.today.year) mdays = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] mdays[2] = 29 if Date.leap?(year)mdays[month] end Simple examples: month_days(1) => 31 month_days(2, 2007) => [...]

Continue Reading

03 August 2007 ~ 9 Comments

Ruby Inject

You probably frequently have to iterate through a list and accumulate a result that changes as you iterate. Let’s take the following array: nums = [1, 3, 5, 7] If you want to find a sum of all the items in the array, you could write something like this: sum = 0 nums.each { |n| [...]

Continue Reading

25 July 2007 ~ 1 Comment

Quick Start with Rails on OS X

Install Ruby OS X (10.4) comes with Ruby 1.8.2 already installed. For a quick start this is OK so let’s install Rails. Install Rails Since Rails comes as gem package, first we need to install RubyGems. Download the latest package from RubyForge and unzip it. Now go to the directory where you unpacked the package [...]

Continue Reading