I'm just starting out w/rails & have a toy app w/just 2 types of
things right now: People and Organizations. Person :belongs_to
organization and Organization :has_many people.
I'd like to provide a select control showing the available
organizations on the people/new and people/edit actions (or whatever
they're called) and so I'm using collection_select to do that. My
question is where to put the call to Organization.find(:all) to grab
out the data I need to populate the select control. It seems like I
should be able to do that just once & stash the results in a class var
for use anyplace in the people controller class.
But when I go to put that list in a class variable in my (scaffold-
generated) people_controller.rb file like so:
class PeopleController < ApplicationController
@@organizations = Organization.find(:all)
# blah blah blah
And then try to access this from views/people/new.html.erb w/this
<%= collection_select(:person, :organization_id,
@@organizations, :id, :name) %>
I get a NameError on that call to collection_select() w/msg
"uninitialized class variable @@organizations in
So... where can I stash the results of that .find(:all) call so that
the same data is available for both actions?