Forum: Ruby on Rails Alphabetically sorted list pages + dynamic forms

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D0cc562dcddc06cb625b62bb571aea3a?d=identicon&s=25 Matt Andrews (Guest)
on 2006-05-20 19:05
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
882cc23c77c5c6d27613c51396a02a0d?d=identicon&s=25 Stephen Bartholomew (Guest)
on 2006-05-20 19:31
(Received via mailing list)
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
<select name="authors" multiple="multiple">
  <%= options_from_collection_for_select @authors, "id", "author" %>
</select>

- in the enter reviews view
<% for author_id in @selected_authors %>
  <!-- review form -->
<% end %>

Hope this helps.

I'll also do the standard recommendation for the Agile book:
http://www.pragmaticprogrammer.com/titles/rails/index.html.

Steve
D0cc562dcddc06cb625b62bb571aea3a?d=identicon&s=25 Matt Andrews (Guest)
on 2006-05-20 20:05
Stephen Bartholomew 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.
882cc23c77c5c6d27613c51396a02a0d?d=identicon&s=25 Stephen Bartholomew (Guest)
on 2006-05-21 11:06
(Received via mailing list)
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
This topic is locked and can not be replied to.