# Simple find works in console but not in controller

**URL:** <https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280>\
**Category:** Rails\
**Created:** [June 12, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280 "2008-06-12T16:18:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/1 "2008-06-12T16:18:09Z")

</div>

I’m still new to rails and trying to figure out why this isn’t  
working. I’ve got a model named Buzzuser. It’s got an a boolean  
column/attribute named npc. At first I tried

Buzzuser.find(:all, :conditions =\> [“npc = ?”, true])

and got no results in the controller, but the same query executing in  
the console returned the correct row. Then I tried a simple

Buzzuser.find(:all)

with the same result: no results in controller, but correct in  
console.

What am I missing?

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/2 "2008-06-12T16:27:05Z")

</div>

On 12 Jun 2008, at 15:17, Brian wrote:

> Buzzuser.find(:all)
> 
> with the same result: no results in controller, but correct in  
> console.

I expect they;re not running the same rails environment (check what it  
says when you run script/server and script/console)

Fred

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 4:41pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/3 "2008-06-12T16:41:14Z")

</div>

I thought that too, but they’re both running in development  
environment.

On Jun 12, 10:26 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 4:47pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/4 "2008-06-12T16:47:08Z")

</div>

How does the SQL output look in development.log  
when you run in console and controller?

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/5 "2008-06-12T16:48:54Z")

</div>

Brian wrote:

> I thought that too, but they’re both running in development  
> environment.

What do your unit tests reveal?

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/6 "2008-06-12T16:51:15Z")

</div>

I don’t know how to view the SQL in the console, but in the dev log  
it’s what I would expect:

SELECT \* FROM `buzzusers`

for the Buzzuser.find(:all), and

SELECT \* FROM `buzzusers` WHERE (npc = 1)

for

Buzzuser.find(:all, :conditions =\> [“npc = ?”, true])

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 5:19pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/7 "2008-06-12T17:19:36Z")

</div>

Nothing. The unit test that runs this same find also successfully  
finds the 2 that were loaded via the fixture.

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 12, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/simple-find-works-in-console-but-not-in-controller/140280/8 "2008-06-12T20:50:58Z")

</div>

more strangeness : if I use the default scaffold views, I can see the  
buzzusers I’m looking for, and the npc = true values. But the find in  
the controller still doesn’t find them. Also, my current user (the  
standard restful\_authentication user guy) has a :has\_one relationship  
to a buzzuser, and that current buzzuser is being found just fine.

Is there any way to get more information on what’s going on during the  
find operation? Could it be swallowing an error? Can I turn up the  
logging on it?

On Jun 12, 10:26 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
