Alphabar on Rails

I am working on this little personal project right now using Ruby on Rails and I ran into some trouble with the alphabar plugin. First, alphabar uses the with_scope method which, since Rails 2.0 I believe, has been protected, giving me some errors since I froze my Rails version. I was able to overcome this obstacle by using the send method instead. Just change the last part of the find method of the plugin from:

model.with_scope({:find => {:conditions => conditions}})
{model.find :all}


model.send(:with_scope, {:find => {:conditions => conditions}})
{model.find :all}

After I finally got that to work the plugin was very useful, although the alphabar was limited to letters and blank which is useful if you don’t need numbers. To accomodate numbers just add this to the alphabar helper:

('0'..'9').to_a.each do |i|
slots << i

Theoretically it should work for any character but I haven’t tried it yet.

So there you have it. Hoepfully somebody having trouble with this plugin will find this post useful.


2 Responses to “Alphabar on Rails”

  1. snowmaninthesun Says:

    This page on getting alphabar up and running along with getting it to work with numbers was an awesome help. I noticed that there’s not much information on exactly how to implement alphabar, right now i have a view that renders 26 different link_to ‘s (a,b,c…z) and directs them to :action => ‘a_z’ where i utilize alphabar and redirect the user to a listing of the results, which still need to be paginated and i intend to do this using will_paginate, is this how alphabar was intended to be utilized, or did I completely miss the point? If so would you be willing to write a short example?

  2. For the most part I think what you have was how Alphabar was meant to be implemented, except for the part where you render the links manually. Alphabar can generate those links for you.

    I haven’t used Alphabar with will_paginate yet. Tell me if it works. I used will_paginate before but the alphabar part was done manually.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: