# Listing items from database with conditions

**URL:** <https://www.ruby-forum.com/t/listing-items-from-database-with-conditions/123369>\
**Category:** Rails\
**Created:** [December 17, 2007, 5:15am UTC](https://www.ruby-forum.com/t/listing-items-from-database-with-conditions/123369 "2007-12-17T05:15:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [December 17, 2007, 5:15am UTC](https://www.ruby-forum.com/t/listing-items-from-database-with-conditions/123369/1 "2007-12-17T05:15:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [December 17, 2007, 11:18am UTC](https://www.ruby-forum.com/t/listing-items-from-database-with-conditions/123369/2 "2007-12-17T11:18:30Z")

</div>

This is great! Thanks Ryan

---

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [December 17, 2007, 5:45am UTC](https://www.ruby-forum.com/t/listing-items-from-database-with-conditions/123369/3 "2007-12-17T05:45:20Z")

</div>

Book.find\_by\_title(params[:title], :order =\> “volume DESC”, :limit =\> 1)

On Dec 17, 2007 2:45 PM, Katsuo I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 2 435 56
> 
> ## List on view Lost 15 Mist 12 Dragon Ball 56
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [December 19, 2007, 7:08am UTC](https://www.ruby-forum.com/t/listing-items-from-database-with-conditions/123369/4 "2007-12-19T07:08:53Z")

</div>

Ryan B. 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?

---

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [December 19, 2007, 7:10am UTC](https://www.ruby-forum.com/t/listing-items-from-database-with-conditions/123369/5 "2007-12-19T07:10:59Z")

</div>

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 I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> @books = Book.find\_by\_title(params[:title], :order =\> “volume DESC”,
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!
