Snippets: Rails 'A'..'Z' Paginate

June 24, 2007 @ 09:40 PM | posted by carmelyne

(last updated: 06.25.07)

'A'..'Z' paging cause I'm being lazy & I don't want to mess around with default paginate.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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]) 
 
# Sort link A-Z / view
<a href="models?sort=A">A</a>

[ Last updated: June 25, 2007 @ 03:49 AM ]

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