Matt Andrews
2006-May-20 17:05 UTC
[Rails] 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 -- Posted via http://www.ruby-forum.com/.
Stephen Bartholomew
2006-May-20 17:29 UTC
[Rails] Alphabetically sorted list pages + dynamic forms
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 Matt Andrews wrote:> 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 >
Matt Andrews
2006-May-20 18:05 UTC
[Rails] Re: Alphabetically sorted list pages + dynamic forms
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. -- Posted via http://www.ruby-forum.com/.
Stephen Bartholomew
2006-May-21 09:05 UTC
[Rails] Re: Alphabetically sorted list pages + dynamic forms
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 Matt Andrews wrote:> 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. >