Why am I getting undefined local variable ''contact'' in my
partial.
This is code I used to render the partial, works in lots of other places
<%= render (:partial => ''list'', :collection =>
@contacts) %>
in my parital I have
<%= contact.first_name %>
if I write this way it works fine
<% for contact in @contacts %>
<%= render (:partial => ''list'', :locals => {:contact
=> contact } ) %>
<% end %>
@contacts is being loaded with a paginate in my controller. any ideas ?
joe
For your render method use :partial => ''contact'' Kent. On 2/7/06, Jebus <lordjebus@gmail.com> wrote:> Why am I getting undefined local variable ''contact'' in my partial. > This is code I used to render the partial, works in lots of other places > > <%= render (:partial => ''list'', :collection => @contacts) %> > > in my parital I have > <%= contact.first_name %> > > if I write this way it works fine > <% for contact in @contacts %> > <%= render (:partial => ''list'', :locals => {:contact => contact } ) %> > <% end %> > > @contacts is being loaded with a paginate in my controller. any ideas ? > > joe > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi Jebus ~ The local variable will have the same name as the partial. So in this case, your local variable is named list. So list.first_name will work. If you want to use contact, rename your partial to _contact.rhtml. ~ Ben On 2/7/06, Jebus <lordjebus@gmail.com> wrote:> Why am I getting undefined local variable ''contact'' in my partial. > This is code I used to render the partial, works in lots of other places > > <%= render (:partial => ''list'', :collection => @contacts) %> > > in my parital I have > <%= contact.first_name %> > > if I write this way it works fine > <% for contact in @contacts %> > <%= render (:partial => ''list'', :locals => {:contact => contact } ) %> > <% end %> > > @contacts is being loaded with a paginate in my controller. any ideas ? > > joe > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com