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

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.
61832b2549d796082a8eb8d54396ab8f?d=identicon&s=25 wintermute (Guest)
on 2007-04-19 21: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
controller)

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,

W
0c660cb450f33249b6b23bcb84f0d63b?d=identicon&s=25 Dylan Markow (Guest)
on 2007-04-20 01:52
<%= render(:partial => "list", :locals => {:list => @list) %>
This topic is locked and can not be replied to.