Created
January 6, 2009 15:33
-
-
Save gerhard/43855 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% @organisations_by_letter.each do |letter| -%> | |
| <li><%= link_to_unless(letter == params[:id], letter, organisation_url(letter)) do |name| | |
| link_to(name, organisation_url(letter), :class => "active") | |
| end %></li> | |
| <% end -%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Organisation < ActiveRecord::Base | |
| # provided through utility_scopes gem http://github.com/yfactorial/utility_scopes/tree/master | |
| # Rails 2.2 EDGE has default scopes | |
| ordered_by "name" | |
| # default_limit '1000' | |
| named_scope :letter, lambda { |letter| {:conditions => conditions(letter) } | |
| def self.conditions(letter) | |
| if letter == "Other" | |
| "name REGEXP '^[[:digit:]]|^[[:space:]]|^[[:punct:]]'" | |
| elsif !letter.blank? | |
| ["name like ?", letter + "%"] | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OrganisationController< ApplicationController | |
| def index | |
| @organisations_by_letter = ("A".."Z").to_a << "Other" # to generate the letters list | |
| params[:id] = "A" if params[:id].nil? || !@organisations_by_letter.include?(params[:id]) | |
| @organisations = Organisation.ordered.letter(params[:id]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment