Hi, I am looking for a way to simplify a listing of books in a database. I do not want to have all the books listed according to certain title but just one book with the latest volume even though there are more than one. Can anyone help me what method or action is needed to accomplish this task? Table for books id(book_id) series_id volume 1 230 4 2 435 56 3 230 12 4 123 12 5 230 12 6 123 15 Table for series id(series_id) series_name 123 Lost 230 Mist 435 Dragon Ball List on view Lost 15 Mist 12 Dragon Ball 56 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Book.find_by_title(params[:title], :order => "volume DESC", :limit => 1) On Dec 17, 2007 2:45 PM, Katsuo Isono <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, I am looking for a way to simplify a listing of books in a database. > I do not want to have all the books listed according to certain title > but just one book with the latest volume even though there are more than > one. Can anyone help me what method or action is needed to accomplish > this task? > > Table for books > id(book_id) series_id volume > 1 230 4 > 2 435 56 > 3 230 12 > 4 123 12 > 5 230 12 > 6 123 15 > > Table for series > id(series_id) series_name > 123 Lost > 230 Mist > 435 Dragon Ball > > List on view > Lost 15 > Mist 12 > Dragon Ball 56 > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is great! Thanks Ryan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> Book.find_by_title(params[:title], :order => "volume DESC", :limit => 1)-------------------------------------------- I''ve created the following method on books.controller and changed series table to title table def list @books = Book.find_by_title(params[:title], :order => "volume DESC", :limit => 1) end However, got this error message; "undefined method `find_by_title'' for Book:Class" Do I have to create find_by_title method on book.rb? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The find_by_title method should be there already, unless you haven''t changed the field to title. On Dec 19, 2007 4:38 PM, Katsuo Isono <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ryan Bigg wrote: > > Book.find_by_title(params[:title], :order => "volume DESC", :limit => 1) > > -------------------------------------------- > > I''ve created the following method on books.controller and changed series > table to title table > > def list > @books = Book.find_by_title(params[:title], :order => "volume DESC", > :limit => 1) > end > > However, got this error message; > > "undefined method `find_by_title'' for Book:Class" > > Do I have to create find_by_title method on book.rb? > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---