François Beausoleil
2005-Jul-06 19:03 UTC
collection_select not selecting the selected item
Hi ! I have Event belongs_to Category. The generated source is: <p><label for="event_category">Category</label><br/> <select id="event_category" name="event[category]"> <option value="8">Introduction</option> <option value="7">Programming</option> </select></p> Notice no values are selected, even there is a selection (7, to be exact). So, I dug up in the Rails code, and I found ActionView::Helpers::InstanceTag#to_collection_select_tag. Except line 4 of this method is: "select", add_blank_option( options_from_collection_for_select( collection, value_method, text_method, value), options[:include_blank]), html_options [split for readability; looking at r1739, line 306: http://dev.rubyonrails.org/svn/rails/trunk/actionpack/lib/action_view/helpers/form_options_helper.rb] I''m wondering where the "value" item is coming from... If I remember correctly, that should invoke self.value in the context of the method, but what value will be returned ? Can someone tell me where I''ve gone wrong ? I have been struggling with this for the past two hours, and it''s driving me nuts :) Thanks ! François
François Beausoleil
2005-Jul-06 19:08 UTC
Re: collection_select not selecting the selected item
Yeah, right... Ten seconds after sending, I found ticket #1125: http://dev.rubyonrails.com/ticket/1125 Shouldn''t there be some kind of AR helper to select from associated objects ? Thanks, François