rails options_from_collection_for_select当前选择值

时间:2011-01-03 14:42:15

标签: ruby-on-rails

我有一个使用

生成的选择表

观点:

<select id = "car_type", name="car_type">
  <%= options_from_collection_for_select @cartype, 'id', 'name' %>      
<select>

在控制器中我有这个

  

@cypeype = Cartype.find(:all)

我需要获取当前选择值,因此我可以根据第一个选项选择生成第二个选择表。我知道这可以用observe_field来完成,但是,observe_field存在一些问题,所以首先我决定使用参数传递。

非常感谢任何提示

任何人都可以指出,我如何获得当前选择值并传递值?

1 个答案:

答案 0 :(得分:2)

正如您在Rails documentation for options_from_collection_for_select中看到的那样,最后一个参数是选定的值,应该是一个整数。 E.g。

options_from_collection_for_select(@people, 'id', 'name', 1)