Alphabetically sorted list pages + dynamic forms

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

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

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.

Steve

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.

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