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!