# Problem with dynamic selects

**URL:** <https://www.ruby-forum.com/t/problem-with-dynamic-selects/166955>\
**Category:** Rails\
**Created:** [May 1, 2009, 11:19am UTC](https://www.ruby-forum.com/t/problem-with-dynamic-selects/166955 "2009-05-01T11:19:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bradherman](https://www.ruby-forum.com/u/bradherman)\
**Post date:** [May 1, 2009, 11:19am UTC](https://www.ruby-forum.com/t/problem-with-dynamic-selects/166955/1 "2009-05-01T11:19:10Z")

</div>

I’m trying to create dynamic select menus for my application. I have a  
partial that is rendered by an action in my site controller after an  
:onchange event is triggered. I’ll post the three pieces of code and  
the error I keep getting.

_\_models.html.haml_

- if models  
= collection\_select :model\_id, models, :id, :name, {:prompt =\> “Select  
Model”}

_site\_controller.rb_  
def update\_models

# update models in dynamic select boxes

make = Make.find(params[:make\_id])  
models = make.models

render :update do |page|  
page.replace\_html ‘models’, :partial =\> ‘models’, :object =\> models  
end  
end

_browse.html.haml_  
.form\_row  
= form.collection\_select :make\_id, Make.find(:all), :id, :name,  
{:prompt =\> “Select Makes”}, {:onchange =\> “#{remote\_function(:url =\>  
{:action =\> “update\_models”}, :with =\> “‘make\_id=’+value”)}”}  
.form\_row#models  
= render :partial =\> ‘models’, :object =\> @models

And from my log:

Processing SiteController#update\_models (for 127.0.0.1 at 2009-05-01  
04:41:13) [POST]  
Parameters:  
{“authenticity\_token”=\>“aOem8MBQboKI/e+KdHjNKgm2DvIQYFCyk14o6TtCj/w=”,  
“make\_id”=\>“1”}  
Asked for a remote server ? true, ENV[“FERRET\_USE\_LOCAL\_INDEX”] is nil,  
looks like we are not the server  
Will use local index.  
using index in C:/Users/Bradley/Documents/Aptana  
Studio/GreenYard\_003/index/development/make  
default field list: [:name]  
e[4;35;1mMake Columns (13.0ms)e[0m e[0mSHOW FIELDS FROM `makes`e[0m  
e[4;36;1mMake Load (1.0ms)e[0m e[0;1mSELECT \* FROM `makes` WHERE  
(`makes`.`id` = 1) e[0m  
Asked for a remote server ? true, ENV[“FERRET\_USE\_LOCAL\_INDEX”] is nil,  
looks like we are not the server  
Will use local index.  
using index in C:/Users/Bradley/Documents/Aptana  
Studio/GreenYard\_003/index/development/model  
default field list: [:name]

ActionView::TemplateError (undefined method `map’ for 🆔Symbol) on  
line #2 of app/views/site/\_models.html.haml:  
1: - if @models  
2: = collection\_select :model\_id, @models.name, :id, :name, {:prompt  
=\> “Select Model”}

```
app/views/site/_models.html.haml:2:in

```

`_run_haml_app47views47site47_models46html46haml_locals_models_object' haml (2.0.9) lib/haml/helpers/action_view_mods.rb:14:in`render’  
app/controllers/site\_controller.rb:46:in `__instance_exec0' app/controllers/site_controller.rb:45:in`update\_models’  
haml (2.0.9) lib/sass/plugin/rails.rb:19:in `process' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in`service’  
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in`start\_thread’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in`start\_thread’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in`each’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start' -e:2:in`load’  
-e:2

Rendered rescues/\_trace (193.0ms)  
Rendered rescues/\_request\_and\_response (1.0ms)  
Rendering rescues/layout (internal\_server\_error)  
es/\_request\_and\_response (1.0ms)  
Rendering rescues/layout (internal\_server\_error)  
e[4;35;1mSQL (1.0ms)e[0m e[0mSET NAMES 'utf8’e[0m  
e[4;36;1mSQL (0.0ms)e[0m e[0;1mSET SQL\_AUTO\_IS\_NULL=0e[0m

Any suggestions? Thanks!

---

<div class="post-metadata">

**Author:** ![bradherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bradherman](https://www.ruby-forum.com/u/bradherman)\
**Post date:** [May 1, 2009, 12:14pm UTC](https://www.ruby-forum.com/t/problem-with-dynamic-selects/166955/2 "2009-05-01T12:14:24Z")

</div>

Hi,  
can you verify parameters to collection\_select. Are they proper?

Regards,  
gaurav

On May 1, 2:19 pm, Bradley H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![bradherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bradherman](https://www.ruby-forum.com/u/bradherman)\
**Post date:** [May 1, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/problem-with-dynamic-selects/166955/3 "2009-05-01T22:51:34Z")

</div>

Okay I solved that, partially. I needed to pass :locals =\> {:form =\>  
form} from my view when first rendering the partial. The problem is,  
though, that on the :onchange event, the partial is rendered through the  
controller, so I can’t pass :locals from there. So after the :onchange  
event, I get the same error with the form.collection\_select throwing a  
“Wrong number of arguments 0 for 1” error.

---

<div class="post-metadata">

**Author:** ![bradherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@bradherman](https://www.ruby-forum.com/u/bradherman)\
**Post date:** [May 1, 2009, 10:09pm UTC](https://www.ruby-forum.com/t/problem-with-dynamic-selects/166955/4 "2009-05-01T22:09:28Z")

</div>

gaurav v bagga wrote:

> Hi,  
> can you verify parameters to collection\_select. Are they proper?
> 
> Regards,  
> gaurav
> 
> On May 1, 2:19ï¿½pm, Bradley H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

After doing some testing, it would appear Rails is just having a major  
problem with my partial. The parameters are fine, but something about  
having that code in a partial is throwing it off. When I replace the  
current stuff with the exact same code that I have in my  
browse.html.haml layout, it messes up and gives me weird errors about  
arguments…

wrong number of arguments (0 for 1)

Extracted source (around line #4):

1: - if @models  
2: = form.collection\_select :model\_id, @models, :id, :name, :prompt =\>  
“Select Model”  
3: - else  
4: = form.collection\_select :model\_id, Model.find(:all), :id, :name,  
{:prompt =\> “Select Model”}

If I leave “form.” off, I get the “undefined method :map for 🆔Symbol  
error” still.
