# Partial not finding variable

**URL:** <https://www.ruby-forum.com/t/partial-not-finding-variable/142548>\
**Category:** Rails\
**Created:** [July 9, 2008, 2:46am UTC](https://www.ruby-forum.com/t/partial-not-finding-variable/142548 "2008-07-09T02:46:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 9, 2008, 2:46am UTC](https://www.ruby-forum.com/t/partial-not-finding-variable/142548/1 "2008-07-09T02:46:41Z")

</div>

Hello - am still very new and need any help available

I have a user model

class User \< ActiveRecord::Base  
has\_many :calls  
has\_many :visits  
has\_many :calls\_visited,  
:through =\> :visits,  
:source =\> :call

has\_many:calls do  
def recent  
find :all, :order =\> ‘id DESC’, :limit =\> 5  
end  
end  
end

and I have a view to display the calls for a particular user using  
a partial  
The view is

## My Dashboard - \<%= @current\_user.login.capitalize %\>

 \<% if @current\_user.calls.blank? %\> 
### You have no calls

- \<%= link\_to 'Add a call to get started!', { :controller =\> "calls", :action =\> "new" } %\>

 \<% else %\>

```
                    <h3>My Recent Calls</h3>
                            <%= render :partial => 'user/

```

recentCalls’, :collection =\> @current\_user.calls.recent %\>  
  
\<% end %\>

 \<% if @current\_user.visits.blank? %\> 
### You have no visits

- \<%= link\_to 'Add a visit to get started!', { :controller =\> "visits", :action =\> "new" } %\>

 \<% else %\> 
### My Recent Visits

 \<% @current\_user.visits.each do |c| %\> - \<%= link\_to c.name, {:controller =\> 'visits', :action =\> 'show', :id =\> c.id} -%\> - _\<%= c.date %\>_
 \<% end %\> 
 \<% end %\> 

 \<%= render :partial =\> 'dashActions' %\>

and the partial that doesn’t work is the user/recentCalls partial

- 
##### \<%= call.created\_at.to\_formatted\_s(:long) %\>

#### \<%= call.name %\>

when the view evaluates \<% if@current\_user.calls.blank? %\> it goes  
through to the

\<%= render :partial =\> ‘user/recentCalls’, :collection =\>  
@current\_user.calls.recent %\>

and throws an error NameError in User#dashboard

Showing user/\_recentCalls.rhtml where line #3 raised:

undefined local variable or method `call’ for #\<ActionView::Base:  
0x2658158\>

Extracted source (around line #3):

1:

-   
2:  
3: 
##### \<%= call.created\_at.to\_formatted\_s(:long) %\>
  
4: 
#### \<%= call.name %\>
  
5: 

Trace of template inclusion: /user/dashboard.rhtm

Any ideas on why it doesn’t get the call? I’ve tried  
current\_user.call.created\_at… and @current\_user and @call et. .  
Anyway any help will be appreciated

---

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 9, 2008, 2:57am UTC](https://www.ruby-forum.com/t/partial-not-finding-variable/142548/2 "2008-07-09T02:57:14Z")

</div>

render creates a local variable for the object(s) passed to it based  
on the filename of the partial. So in ‘user/\_recentCalls’, passing the  
collection would result in a local variable named ‘recentCall’.

See the API docs for more info:  
[http://api.rubyonrails.org/classes/ActionView/Partials.html](http://api.rubyonrails.org/classes/ActionView/Partials.html)

---

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 9, 2008, 3:23am UTC](https://www.ruby-forum.com/t/partial-not-finding-variable/142548/3 "2008-07-09T03:23:34Z")

</div>

I looked that up and thanks for the reply but I still don’t understand  
what I should write in my render code to call the partial  
and then how my \_recentCalls partial  
should be referenced in the partial template? any suggestions will be  
appreciated!!

Thanks - Owen

---

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 11, 2008, 5:12am UTC](https://www.ruby-forum.com/t/partial-not-finding-variable/142548/4 "2008-07-11T05:12:42Z")

</div>

Thanks for all the help - I think I got it working now

---

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 10, 2008, 1:23am UTC](https://www.ruby-forum.com/t/partial-not-finding-variable/142548/5 "2008-07-10T01:23:18Z")

</div>

You could name your partial just “call” or…

At the start of it do:

\<% call = recentCall %\>

I would reccomend doing it the first way.

---

<div class="post-metadata">

**Author:** ![THEBIGO](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@THEBIGO](https://www.ruby-forum.com/u/THEBIGO)\
**Post date:** [July 10, 2008, 2:04am UTC](https://www.ruby-forum.com/t/partial-not-finding-variable/142548/6 "2008-07-10T02:04:18Z")

</div>

You could name your partial just “call” or…

At the start of it do:

\<% call = recentCall %\>

I would recomend doing it the first way.
