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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Feb-09 02:22 UTC
Re: a SELECT join query; does it go in the controller?
On 9 Feb 2008, at 02:01, Thufir wrote:> > 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> > 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 > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sat, 09 Feb 2008 02:22:02 +0000, Frederick Cheung 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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---