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

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

On 13 Feb 2008, at 10:57, Aditya S. wrote:

head -n 25 | tail -n 3
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

And 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

On Wed, 13 Feb 2008 12:06:05 +0000, Frederick C. wrote:

And show should be

Thank you :slight_smile:

Is it ok (the convention) to put that
in there? I need to add a
title, and start putting things into nice columns and stuff, but one
step
at a time :slight_smile:

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

26 <% end %>
thufir@arrakis ~/goodfellow-tool $

thanks,

Thufir

On Wed, 13 Feb 2008 11:57:37 +0100, Aditya S. 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.

thanks,

Thufir

On Feb 13, 6:06 pm, Frederick C. [email protected]
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

On 13 Feb 2008, at 17:55, Thufir wrote:

logins_controller.rb -n | head -n 18 | tail -n 4
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

On 14 Feb 2008, at 05:46, Thufir wrote:

On Feb 13, 6:06 pm, Frederick C. [email protected]
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