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

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

    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

    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

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

    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.