a SELECT join query; does it go in the controller?

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

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

.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

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'

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

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 :slight_smile:

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

-Thufir