Re: Building a Glossary from a Legacy DB

I would try sticking with the default pagination and seeing if that works for you. Most likely it will be fast enough. Or are you dealing with thousands/millions of records?

Railscasts - Free Ruby on Rails Screencasts

Re: Building a Glossary from a Legacy DB

I have about 12,000 records I am juggling around, so performance is a concern

Re: Building a Glossary from a Legacy DB

Oh, I see. Sounds like the plugin is a better bet then. smile

Railscasts - Free Ruby on Rails Screencasts

Re: Building a Glossary from a Legacy DB

I am a bit confused how this should fit in with my current index action:

  
def letter               
  case params[:letter]
    when "numbers"
      @terms = Term.first_letter(['.'] + ('0'..'9').to_a)       
    when /^[a-z]$/i
      @terms = Term.first_letter(params[:letter])     
    else
      redirect_to '/terms/a'
    end       
end

Should I extract this case statement into another method?

Last edited by pimpmaster (2007-05-04 12:23:11)

Re: Building a Glossary from a Legacy DB

You need to move the find out of the case statement so you're only doing the find in one place. Then it should become clearer:

# in controller

def letter
  if first_letter_param.nil?
    redirect_to 'terms/a'
  else
    Term.first_letter(first_letter_param) do
      @terms = Term.find....
    end
  end
end

protected

def first_letter_param
  case params[:letter]
  when "numbers"
    ['.'] + ('0'..'9').to_a
  when /^[a-z]$/i
    params[:letter]
  end
end


might want to rename that method.

Railscasts - Free Ruby on Rails Screencasts

Re: Building a Glossary from a Legacy DB

I got it working in a surprisingly short amount of time. At first I had trouble because the pagination was mucking up my :letter params with pg=1..bad news.

I managed to fix that by setting up the following route

map.connect 'terms/:letter/:page', :controller => 'terms', :action => 'letter', :page => 1

Everything works stupendously. Your find method was the ticket.

PS - If you are ever in Barcelona, I owe you a crate of beer!

big_smile