rails 2.1.2 collection_select with an :onchange and a :with
After a lot of searching and reading I've got a collection_select that looks like so
<%= collection_select :selection, :level, User::LEVELS, :to_s, :to_s,{:with => "this.value"},
{:onchange => remote_function(
:url => {:action => "updatelevel", :controller => "user", :id=> user.id})
} %开发者_开发技巧>
However its not passing the selected value to my controller, the only thing I've ever got is a nil.
I've messed about with difference combinations of where :with should be and tried test strings but it never seems to do anything.
Am I missing something stupid? Is there a "definative" example I should be looking at?
Rails seems to change so fast that its hard to know which version a forum post is talking about and the api I read for collection_select doesn't show what I can put in the options hash.
I checked this out on my app running Rails 2.3.10. You have your 'with' parameter in the wrong spot, it is an option for the remote function, not for the collection select. Also, passing the value in that manner will get you a params hash that looks like {"134523456" => ""}, which probably isn't what you want. You have to have your 'with' value result in a string that is JavaScript centric.
<%= collection_select :selection, :level, User::LEVELS, :to_s, :to_s, {},
{:onchange => remote_function(
:url => {:action => "updatelevel", :controller => "user", :id=> user.id},
:with => "'level_id='+this.value"
)
}
%>
精彩评论