Snippets: Ruby Switch Statements

June 20, 2007 @ 10:47 AM | posted by carmelyne

(last updated: 06.24.07)

1
2
3
4
5
case foo
   when 1    then puts "Foo is equal to 1"
   when 2..9 then puts "Foo is between 2 and 9"
   when 10   then puts "Foo is equal to 10"
end

Source: http://railsforum.com/viewtopic.php?pid=27834#p27834

[ Last updated: June 24, 2007 @ 11:06 PM ]

Sorry, comments are closed for this article.

Snippets of 06/24/07

Rails 'A'..'Z' Paginate

1
2
3
4
5
6
7
8
9
10
11
# Starts with 'A'..'Z' Paginate / model
def self.sort(sort)
  if sort
    find(:all, :conditions => ['name LIKE ?', "#{sort}%"])
  else
    find(:all, :order => 'name')
  end  
end

# index action / controller
@models = Model.sort(params[:sort]) 

Recent Posts...

RailsConf 2006
I heart devChix