9 Jul 02:32
Partial not finding variable
From: THEBIGO <Mowenhmad@...>
Subject: Partial not finding variable
Newsgroups: gmane.comp.lang.ruby.rails
Date: 2008-07-09 00:32:57 GMT
Subject: Partial not finding variable
Newsgroups: gmane.comp.lang.ruby.rails
Date: 2008-07-09 00:32:57 GMT
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 c.name, {:controller => 'visits', :action =>
'show', :id => c.id} -%> - <em><%= c.date %></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
<li>
<h5><%= call.created_at.to_formatted_s(:long) %></h5>
<h4><%= call.name %></h4>
</li>
when the view evaluates <% if <at> 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><%= call.name %></h4>
5: </li>
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
--~--~---------~--~----~------------~-------~--~----~
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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
RSS Feed