Thufir
2008-Feb-13 10:42 UTC
iterating through an array of calls to which a login belongs to
There''s an array of calls in the controller to which this login belongs to. The desired output is the comment attribute for these Call instances. I''m getting an error of: undefined local variable or method `calls'' which is perhaps due to a syntax or other erb error in the show: thufir@arrakis ~/goodfellow-tool $ cat app/controllers/ logins_controller.rb -n | head -n 18 | tail -n 4 15 def show 16 @login = Login.find(params[:id]) 17 calls = @login.calls 18 end thufir@arrakis ~/goodfellow-tool $ cat app/views/logins/show.rhtml -n | head -n 25 | tail -n 3 23 <% calls.each do |call| %> 24 <%=h @call.comment %> 25 <% end %> thufir@arrakis ~/goodfellow-tool $ cat app/models/call.rb class Call < ActiveRecord::Base belongs_to :login end thufir@arrakis ~/goodfellow-tool $ cat app/models/login.rb class Login < ActiveRecord::Base belongs_to :employee has_many :calls end 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 -~----------~----~----~----~------~----~------~--~---
Aditya Sanghi
2008-Feb-13 10:57 UTC
Re: iterating through an array of calls to which a login bel
Thufir wrote:> thufir@arrakis ~/goodfellow-tool $ cat app/controllers/ > logins_controller.rb -n | head -n 18 | tail -n 4 > 15 def show > 16 @login = Login.find(params[:id]) > 17 calls = @login.calls > 18 end > thufir@arrakis ~/goodfellow-tool $ cat app/views/logins/show.rhtml -n | > head -n 25 | tail -n 3 > 23 <% calls.each do |call| %> > 24 <%=h @call.comment %> > 25 <% end %> > thufir@arrakis ~/goodfellow-tool $ cat app/models/call.rb > class Call < ActiveRecord::Base > belongs_to :login > end > thufir@arrakis ~/goodfellow-tool $ cat app/models/login.rb > class Login < ActiveRecord::Base > belongs_to :employee > has_many :calls > end > thufir@arrakis ~/goodfellow-tool $ >Hi Thufir, You are missing the @ symbol on line 17 in your logins_controller. it should be @calls = @login.calls -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-13 12:06 UTC
Re: iterating through an array of calls to which a login bel
On 13 Feb 2008, at 10:57, Aditya Sanghi wrote:> > Thufir wrote: >> thufir@arrakis ~/goodfellow-tool $ cat app/controllers/ >> logins_controller.rb -n | head -n 18 | tail -n 4 >> 15 def show >> 16 @login = Login.find(params[:id]) >> 17 calls = @login.calls >> 18 end >> thufir@arrakis ~/goodfellow-tool $ cat app/views/logins/show.rhtml - >> n | >> head -n 25 | tail -n 3 >> 23 <% calls.each do |call| %> >> 24 <%=h @call.comment %> >> 25 <% end %> >> thufir@arrakis ~/goodfellow-tool $ cat app/models/call.rb >> class Call < ActiveRecord::Base >> belongs_to :login >> end >> thufir@arrakis ~/goodfellow-tool $ cat app/models/login.rb >> class Login < ActiveRecord::Base >> belongs_to :employee >> has_many :calls >> end >> thufir@arrakis ~/goodfellow-tool $ >> > Hi Thufir, > > You are missing the @ symbol on line 17 in your logins_controller. it > should be > @calls = @login.callsAnd show should be <% @calls.each do |call| %> <%=h call.comment %> <% end %> As it is, you''re iterating over something that doesn''t exist, and on top of that the block was yielding you one value but you were using another. Fred> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 Wed, 13 Feb 2008 12:06:05 +0000, Frederick Cheung wrote:> And show should beThank you :) Is it ok (the convention) to put that <br> in there? I need to add a title, and start putting things into nice columns and stuff, but one step at a time :) thufir@arrakis ~/goodfellow-tool $ cat app/views/logins/show.rhtml -n | head -n 26 | tail -n 4 23 <% @calls.each do |call| %> 24 <%=h call.comment %> 25 <br> 26 <% end %> 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 Wed, 13 Feb 2008 11:57:37 +0100, Aditya Sanghi wrote:> You are missing the @ symbol on line 17 in your logins_controller. it > should be > @calls = @login.callsThanks, I corrected it to: thufir@arrakis ~/goodfellow-tool $ cat app/controllers/ logins_controller.rb -n | head -n 18 | tail -n 4 15 def show 16 @login = Login.find(params[:id]) 17 @calls = @login.calls 18 end thufir@arrakis ~/goodfellow-tool $ What I don''t understand is that there''s a Call class (model), but there''s no Calls model. How in the world can there be an instance of a class, Calls, which doesn''t exist? Clearly, class Calls does exist -- this must be the magic of rails, what rails does for me. I dunno, too easy. 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-14 02:06 UTC
Re: iterating through an array of calls to which a login bel
On 13 Feb 2008, at 17:55, Thufir wrote:> > On Wed, 13 Feb 2008 11:57:37 +0100, Aditya Sanghi wrote: > >> You are missing the @ symbol on line 17 in your logins_controller. it >> should be >> @calls = @login.calls > > Thanks, I corrected it to: > > thufir@arrakis ~/goodfellow-tool $ cat app/controllers/ > logins_controller.rb -n | head -n 18 | tail -n 4 > 15 def show > 16 @login = Login.find(params[:id]) > 17 @calls = @login.calls > 18 end > thufir@arrakis ~/goodfellow-tool $ > > > What I don''t understand is that there''s a Call class (model), but > there''s > no Calls model. How in the world can there be an instance of a class, > Calls, which doesn''t exist? > > Clearly, class Calls does exist -- this must be the magic of rails, > what > rails does for me. I dunno, too easy. >There is no Calls class. what makes you think here is one ? Fred> > 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 Feb 13, 6:06 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: [...]> There is no Calls class. what makes you think here is one ?When the show uses @shows, doesn''t the "@" indicate instance variable? I would think that @shows is an array, and yes it''s an object so, in that sense, I guess, is an instance variable of Array. Why is the "@" required in this case? -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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Feb-14 07:10 UTC
Re: iterating through an array of calls to which a login bel
On 14 Feb 2008, at 05:46, Thufir wrote:> > On Feb 13, 6:06 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > [...] >> There is no Calls class. what makes you think here is one ? > > When the show uses @shows, doesn''t the "@" indicate instance > variable? I would think that @shows is an array, and yes it''s an > object so, in that sense, I guess, is an instance variable of Array. >Well yes @calls is an instance variable (of an instance of your controller), but that''s got nothing to do with their being or not a Calls class. And it''s definitely not an instance variable of Array (unless you meant that it''s an instance variable that happens to be an array)> Why is the "@" required in this case?Well if there was no @ then it wouldn''t be an instance variable and so your view wouldn''t be able to play with it Fred> > -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 -~----------~----~----~----~------~----~------~--~---