# A SELECT join query; does it go in the controller?

**URL:** <https://www.ruby-forum.com/t/a-select-join-query-does-it-go-in-the-controller/128594>\
**Category:** Rails\
**Created:** [February 9, 2008, 3:02am UTC](https://www.ruby-forum.com/t/a-select-join-query-does-it-go-in-the-controller/128594 "2008-02-09T03:02:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 9, 2008, 3:02am UTC](https://www.ruby-forum.com/t/a-select-join-query-does-it-go-in-the-controller/128594/1 "2008-02-09T03:02:13Z")

</div>

If I understand MVC correctly, basically the SQL statement below can be  
“translated” to ruby as a method in the controller, then called from the  
view.

I have a “report” method in my controller which I’m trying to call from  
the view, but it’s presently giving an error of:

undefined method `report’

thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ sqlite3 db/development.sqlite3  
SQLite version 3.4.1  
Enter “.help” for instructions  
sqlite\> SELECT calls.comment,calls.created\_at,logins.login FROM  
calls,logins WHERE calls.login\_id=1 AND logins.id=1;  
start work|2008-02-08 15:12:13|0123  
start call|2008-02-08 15:12:13|0123  
start break|2008-02-08 15:12:13|0123  
sqlite\> .quit  
thufir@arrakis ~/goodfellow-tool $ cat -n app/controllers/  
calls\_controller.rb | head -n 56 | tail -n 3  
54 def report  
55 @calls=Call.find(:all, :include =\> [:logins, :login])  
56 end  
thufir@arrakis ~/goodfellow-tool $ cat -n app/views/calls/show.rhtml |  
head -n 7 | tail -n 1  
7 \<%= @call.report %\>  
thufir@arrakis ~/goodfellow-tool $ rails --version  
Rails 1.2.5  
thufir@arrakis ~/goodfellow-tool $

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 9, 2008, 3:22am UTC](https://www.ruby-forum.com/t/a-select-join-query-does-it-go-in-the-controller/128594/2 "2008-02-09T03:22:43Z")

</div>

On 9 Feb 2008, at 02:01, Thufir wrote:

> undefined method `report’

Um, you appear to have everything mixed up. You’re defining a method  
on a controller (such methods aren’t accessible from views, unless you  
play around with helper\_method), and then you’re trying to call that  
method on an instance of Call ? On top of that, I’d put something like  
that in a model.

Fred

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 9, 2008, 7:10am UTC](https://www.ruby-forum.com/t/a-select-join-query-does-it-go-in-the-controller/128594/3 "2008-02-09T07:10:05Z")

</div>

On Sat, 09 Feb 2008 02:22:02 +0000, Frederick C. wrote:

> Um, you appear to have everything mixed up. You’re defining a method on  
> a controller (such methods aren’t accessible from views, unless you play  
> around with helper\_method), and then you’re trying to call that method  
> on an instance of Call ? On top of that, I’d put something like that in  
> a model.

I thought that I conceptually grasped MVC – guess not. However, I do  
know that I have the model and schema correctly configured because I can  
get good output through the console:

thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ script/console  
Loading development environment.  
[…]

> > calls\_logins.each {|event| puts event.login.login + “\t” +  
> > event.created\_at.to\_s + “\t” + event.comment}  
> > 0123 Fri Feb 08 15:12:13 -0800 2008 start work  
> > 0123 Fri Feb 08 15:12:13 -0800 2008 start call  
> > 0123 Fri Feb 08 15:12:13 -0800 2008 start break  
> > […]

So, that’s good 🙂

I’m working on what method to put in the model.

-Thufir
