Forum: Ruby on Rails render collection undefined local variable

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jebus (Guest)
on 2006-02-07 23:34
(Received via mailing list)
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
Kent S. (Guest)
on 2006-02-07 23:37
(Received via mailing list)
For your render method use

:partial => 'contact'

Kent.
Ben R. (Guest)
on 2006-02-07 23:37
(Received via mailing list)
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 <removed_email_address@domain.invalid> wrote:
> <%= render (:partial => 'list', :locals => {:contact => contact } ) %>
> <% end %>
>
> @contacts is being loaded with a paginate in my controller. any ideas ?
>
> joe
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben R.
http://www.benr75.com
This topic is locked and can not be replied to.