Forum: Ruby on Rails Controller class variables not available to method partials?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
wintermute (Guest)
on 2007-04-19 23:12
(Received via mailing list)
Hi all,

I hope I got the title right. Here is my noob problem. I have one
controller 'user' and a layout for it (also 'user'). This layout
displays 3 columns side by side:

- a search box on the left that shows results via view in /user/search
(through method 'search' in controller)
- a display column (through :yield in the controller)
- a shopping list of items with any changes (through a partial in the

My problem is in the shopping list. The partial is rendered using:

     <%= render(:partial => "list", :object => @list) %>

Where @list is a controller class variable. However when I invoke the
search action I get this error:

     NoMethodError in User#search
     Showing app/views/user/_list.rhtml where line #3 raised:

     You have a nil object when you didn't expect it!
     The error occurred while evaluating nil.items

So I guess the @list array is unavailable in the search view? Does
search not inherit from the controller? How can I make it see @list.

Thanks in advance, sorry if this is really easy,

Dylan M. (Guest)
on 2007-04-20 03:52
<%= render(:partial => "list", :locals => {:list => @list) %>
This topic is locked and can not be replied to.