Hello,
I am having difficulty with extracting data from the collection_select
form helper.
First, the code:
-
view ->>
<%= collection_select :colors, :id, send_colors, :id, :color %> -
view helper that polulates collection_select ‘send_colors’ -->>
def send_colors
@colors = Color.find(:all)
end -
controller ->>
def create
@color = Color.new(params[:color])
end
My problem is that when I submit the form, @color (in the controller) is
not being populated with any data. I have inspected the @color object
and it’s attributes are empty. When I view the HTML source in the web
browser, the select form value options are there but seemingly not
submitted back to controller. Perhaps my controller code is wrong.
Also, here’s some debug YAML output
<%= debug(params) %>
— !map:HashWithIndifferentAccess
commit: Save changes
action: create_debug
controller: admin
color: !map:HashWithIndifferentAccess
id: “1”
<%= debug(@color) %>
— !ruby/object:Color
attributes:
color:
new_record: true
<%= debug(request) %>
partial output
#<ActionController::CgiRequest:0x3604d40 @parameters={“commit”=>“Save
changes”, “action”=>“create_debug”, “controller”=>“admin”,
“color”=>{“id”=>“1”}},
What is this ‘HasWithIndifferentAccess’ about? Is this my problem?
Thanks for any assistance in advance!