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@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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Jul 8, 5:32 pm, THEBIGO <Mowenh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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@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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Jul 8, 5:56 pm, bspaulding <brad.spauld...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > On Jul 8, 5:32 pm, THEBIGO <Mowenh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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@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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could name your partial just "call" or... At the start of it do: <% call = recentCall %> I would recomend doing it the first way. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for all the help - I think I got it working now On Jul 9, 5:04 pm, Ryan Bigg <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You could name your partial just "call" or... > > At the start of it do: > > <% call = recentCall %> > > I would recomend doing it the first way.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---