rails 2.1.2 collection_select with:onchange和a:with

Sti*_*boy 4 ruby ruby-on-rails

经过大量的搜索和阅读后,我得到了一个看起来像这样的collection_select

<%= collection_select :selection, :level, User::LEVELS, :to_s, :to_s,{:with => "this.value"},
         {:onchange => remote_function(
             :url => {:action => "updatelevel", :controller => "user", :id=> user.id})
         } %>
Run Code Online (Sandbox Code Playgroud)

然而它没有将所选值传递给我的控制器,我唯一得到的就是零.

我已经搞砸了其中的不同组合:应该和尝试测试字符串但它似乎永远不会做任何事情.

我错过了一些愚蠢的东西吗?我应该看一下"具有挑战性"的例子吗?

Rails似乎变化如此之快以至于很难知道论坛帖子正在讨论哪个版本,而我为collection_select读取的api并没有显示我可以在options hash中添加的内容.

Bli*_*zzo 5

我在运行Rails 2.3.10的应用程序上查看了这个.您的'with'参数位于错误的位置,它是远程功能的选项,而不是集合选择.此外,以这种方式传递值将获得一个看起来像{"134523456"=>""}的params哈希,这可能不是你想要的.您必须将"with"值结果放在以JavaScript为中心的字符串中.

<%= 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"
      )
    }
%>
Run Code Online (Sandbox Code Playgroud)