Hi,
I’m very new with Ruby and Rails. I have read Agile Web D.
with Rails and was trying to create a grouped selection list by
following his example on page 359.
My helper looks like this:
module LoginHelper
AssocOption = Struct.new(:code_name, :display_name)
class AssocType
attr_reader :type_name, :options
def initialize(name)
@type_name = name
@options = []
end
def <<(option)
@options << option
end
end
none = AssocType.new(“NONE”)
none << AssocOption.new(“None”, “None”)
none << AssocOption.new(“All”, “All”)
dr = AssocType.new(“DOCTORS”)
dr << AssocOption.new(“Dr. Dave”, “Dave Pancost”)
dr << AssocOption.new(“Dr. Dan”, “Daniel Foreman”)
dr << AssocOption.new(“Dr. Mike”, “Michael Carney”)
co = AssocType.new(“COMPANIES”)
co << Assoc.Option.new(“Sidekick Design”, “Sidekick Design”)
co << Assoc.Option.new(“Strategic Web Concepts”, “Strategic Web
Concepts”)
ASSOCIATION_OPTIONS = [ none, dr, co ]
end
My View looks like this:
<select name="user[associationl]" id="user_association">
<%=
option_groups_from_collection_for_select(ASSOCIATION_OPTIONS,
:options, :type_name,
:code_name, :display_name,
@user.level)
%>
</select>
The error message I’m getting is this:
uninitialized constant ASSOCIATION_OPTIONS
Extracted source (around line #23):
20: -->
21:
22: <%=
23: option_groups_from_collection_for_select(ASSOCIATION_OPTIONS,
24: :options, :type_name,
25: :code_name, :display_name,
26: @user.level)
My question: Didn’t I initialize ASSOCIATION_OPTIONS in the helper?
What did I do wrong and how to I get the group select to work? I tried
to follow exactly what I read in the book, but it doesn’t seem to work,
so I’m assuming I did something wrong, I just can’t quite see what it
is.
Any suggestions?
Thanks,
Dave