Select include_blank alternative

I’m trying to create a list of options with the top item returning “”
while displaying none

<%= select (:activity, :location_state, [[“None”,""]]+
@client.location_addresses.map {|location|
[location.state,location.state]}.uniq.sort, {:selected =>
@location_state_selected }) %>

This generates what I would think would be the right option tags (and
they look right in show source as well) but when it’s returned to the
server :location_state => “None” insead of “”

What gives? Any ideas?

Thanks,
-dustin

Hi. Try write [["", “None”]]
first - value, second - the displaying string.

Another way - using parameter :prompt => “None”, in your case:

<%= select (:activity, :location_state,
@client.location_address.map{|location| [location.state,
location.state]}.uniq.sort, {:prompt => “None”}, {:selected =>
@location_state_selected}) %>

Best Regards, Sergey

Hmm I figured out where the problem is coming from. I’m using
observe_form to watch for changes in this form. The params that are
getting to the :url in observe_form are wrong. I’ve written a simple
test case:

Two rhtml files will show what I’m talking about:

params_test.rhtml:

<title>params</title>
<%= javascript_include_tag "prototype" %>
<%= form_tag ({:action => "render_params"}, {:id => 'form'}) %> <%= select (:activity, :location_type, [["Store","0"], ["DC", "1"]], {:prompt => "None"}) %> <%= submit_tag %>

<%= observe_form(:form,
:update => ‘params’,
:url => {:action => ‘render_params’}) %>

render_params:

<title>render_params</title>

params:

<%= debug(params) %>
request.params:

<%= debug(request.params) %>

Now if I submit the form render_params returns:
params:
— !map:HashWithIndifferentAccess
commit: Save changes
activity: !map:HashWithIndifferentAccess
location_type: “”
action: render_params
controller: params_test
request.params:

commit:

  • Save changes
    activity[location_type]:
  • “”

If I change the form the ‘params’ div gets updated with:
— !map:HashWithIndifferentAccess
commit: Save changes
activity: !map:HashWithIndifferentAccess
location_type: None
action: render_params
controller: params_test
request.params:

commit:

  • Save changes
    activity[location_type]:
  • None

Notice activity[location_type] is “None”! Argh!!! What is going on
here???

Thanks for any and all help,
-dustin

Weird it was a bug with the prototype library that shipped with Rails
on Locomotive. I updated my prototype.js file (which is smaller than
the one that was in public/javascripts/) and it started working.
Should I report a bug somewhere to someone (Locomotive?)

-dustin