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}
to:
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
end
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.
This entry was posted on April 14, 2008 at 11:48 pm and is filed under Programming with tags alphabar, ruby on rails. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
June 7, 2008 at 12:21 pm
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?
June 11, 2008 at 9:42 am
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.