Partial not finding variable

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

<div id="top_full">     <h2>My Dashboard - <%= @current_user.login.capitalize %></h2> </div> <div id="c_left">   <div id="recentCalls">     <% if @current_user.calls.blank? %>         <h3>You have no calls</h3>         <ul>           <li><%= link_to 'Add a call to get started!', { :controller => "calls", :action => "new" } %></li>         </ul>     <% else %>

                        <h3>My Recent Calls</h3>                                 <%= render :partial => 'user/ recentCalls', :collection => @current_user.calls.recent %>       </ul>     <% end %>   </div>   <div id="recentVisits">       <% if @current_user.visits.blank? %>           <h3>You have no visits</h3>           <ul>             <li><%= link_to 'Add a visit to get started!', { :controller => "visits", :action => "new" } %></li>           </ul>       <% else %>           <h3>My Recent Visits</h3>         <ul>           <% @current_user.visits.each do |c| %>               <li><%= link_to, {:controller => 'visits', :action => 'show', :id =>} -%> - <em><%= %></em></li>             <% end %>         </ul>       <% end %>   </div> </div>

<div id="c_right">   <%= render :partial => 'dashActions' %> </div>

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


  <h5><%= call.created_at.to_formatted_s(:long) %></h5>         <h4><%= %></h4> </li>

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: <li> 2: 3: <h5><%= call.created_at.to_formatted_s(:long) %></h5> 4: <h4><%= %></h4> 5: </li>

Trace of template inclusion: /user/dashboard.rhtm

Any ideas on why it doesn't get the call? I've tried and @current_user and @call et. . Anyway any help will be appreciated

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:

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

You could name your partial just "call" or...

At the start of it do:

<% call = recentCall %>

I would reccomend doing it the first way.

You could name your partial just "call" or...

At the start of it do:

<% call = recentCall %>

I would recomend doing it the first way.

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