# Alphabetically sorted list pages + dynamic forms

**URL:** <https://www.ruby-forum.com/t/alphabetically-sorted-list-pages-dynamic-forms/61134>\
**Category:** Rails\
**Created:** [May 20, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/alphabetically-sorted-list-pages-dynamic-forms/61134 "2006-05-20T19:05:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Andrews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@Matt\_Andrews](https://www.ruby-forum.com/u/Matt_Andrews)\
**Post date:** [May 20, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/alphabetically-sorted-list-pages-dynamic-forms/61134/1 "2006-05-20T19:05:26Z")

</div>

Hey everyone,

I’m new to RoR - how can I get my database content filtered by alphabet?  
Eg, on my php site now I use this format:

[http://www.scenepointblank.com/reviews/index.php?page=B](http://www.scenepointblank.com/reviews/index.php?page=B)

How can I get this kind of functionality out of ruby?

Also, how could I go about making a multiple select box of authors, then  
depending on how many you chose, the next page of the form displays a  
“review” textarea and “score” textbox for each author? I’ve done this in  
PHP but figure there’s a better way here.

Matt

---

<div class="post-metadata">

**Author:** ![Matt\_Andrews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@Matt\_Andrews](https://www.ruby-forum.com/u/Matt_Andrews)\
**Post date:** [May 20, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/alphabetically-sorted-list-pages-dynamic-forms/61134/2 "2006-05-20T19:31:57Z")

</div>

Hi,

> how can I get my database content filtered by alphabet?  
> This depends on which fields you want filtered and what your db layout  
> is, but basically you would need to find albums with the specified  
> letter at the beginning of the artist name:

Album.find(:all, :conditions =\> ["artist LIKE ‘?%’ ", params[:letter]])

As for the multiple select box of authors, i would think you’d do  
something like this:

- in your controller

def select\_author

# get all authors to display on the page in a multi select box

@authors = Authors.find(:all)  
end

def enter\_reviews  
@selected\_authors = params[:authors]  
end

- in the select author view  
  
\<%= options\_from\_collection\_for\_select @authors, “id”, “author” %\>  

- in the enter reviews view  
\<% for author\_id in @selected\_authors %\>

\<% end %\>

Hope this helps.

I’ll also do the standard recommendation for the Agile book:  
[http://www.pragmaticprogrammer.com/titles/rails/index.html](http://www.pragmaticprogrammer.com/titles/rails/index.html).

Steve

---

<div class="post-metadata">

**Author:** ![Matt\_Andrews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@Matt\_Andrews](https://www.ruby-forum.com/u/Matt_Andrews)\
**Post date:** [May 20, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/alphabetically-sorted-list-pages-dynamic-forms/61134/3 "2006-05-20T20:05:19Z")

</div>

Stephen B. wrote:

> This depends on which fields you want filtered and what your db layout  
> is, but basically you would need to find albums with the specified  
> letter at the beginning of the artist name:
> 
> Album.find(:all, :conditions =\> ["artist LIKE ‘?%’ ", params[:letter]])

Thanks - whereabouts would this code go, though?

Thanks for the other advice, I’ll give that a try.

---

<div class="post-metadata">

**Author:** ![Matt\_Andrews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5e925/32.png) [@Matt\_Andrews](https://www.ruby-forum.com/u/Matt_Andrews)\
**Post date:** [May 21, 2006, 11:06am UTC](https://www.ruby-forum.com/t/alphabetically-sorted-list-pages-dynamic-forms/61134/4 "2006-05-21T11:06:51Z")

</div>

That code would go in your controller in the action that carries out the  
list:

def list  
@albums = Album.find(:all, :conditions =\> ["artist LIKE ‘?%’ ",  
params[:letter]])  
end

Steve
