Here is what I have:
add_core_content.rhtml:
<select id="resource_core_content_ids"
name="resource[core_content_ids][]" size="15"
style="width: 200px;"
multiple="multiple">
<% @core_contents.each do |c| %>
<option value="<%= c.id %>" <% if
@resource.core_contents.include?
(c) %> selected="selected"<% end %>>
<%= c.code %>
</option>
<% end %>
</select>
<br/>
admin_controller.rb:
def add_core_content
@core_contents =
CoreContent.find_all_by_subject(@params["subject"],
:order => ''level ASC'')
end
Everything works fine if I don''t have:
<% if @resource.core_contents.include? (c) %>
selected="selected"<% end
%>
But when that is included I get an error:
You have a nil object when you didn''t expect it!
The error occured while evaluating nil.core_contents
Extracted source (around line #3):
1: <select id="resource_core_content_ids"
name="resource[core_content_ids][]" size="15"
style="width: 200px;"
multiple="multiple">
2: <% @core_contents.each do |c| %>
3: <option value="<%= c.id %>" <% if
@resource.core_contents.include? (c) %> selected="selected"<%
end %>>
4: <%= c.code %>
5: </option>
6: <% end %>
My many-to-many is core_contents_resources any my models are set up
correctly (having the habtm in both models). I know that I am getting
something with @resource.core_contents because I get information
returned (albeit unreadable,
#<CoreContent:0x3321598>#<CoreContent:0x3321550>#<CoreContent:0x3321508>
#<CoreContent:0x33214c0>)
Thanks,
Seth
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060302/2b941cc6/attachment-0001.html