newbie:simpleform,如何为集合输入字段设置id?

时间:2012-08-30 18:21:55

标签: ruby-on-rails ruby-on-rails-3 simple-form

How would one set:id => “myvalue”用于simpleform 集合输入字段? 或者在旁注上,我也试图设置age_from的ID,如id => “age_from”无法弄清楚如何做到这两点,似乎很缺乏这方面的文档。

尝试了所有可能的组合:

= f.input_field :age_to,
  :label => "Age from",
  :collection => 18..60,
  :select => 19 <------- set this to '19' for this collection?
  :style => "width: 50px !important",
  :id => "myid" <------- how to set id for this collection?

3 个答案:

答案 0 :(得分:6)

f.input_field :age_to, :label => "Age from", :collection => 18..60, 
:selected => 19, :style => "width: 50px !important", :input_html => { :id => "myid" }

希望设置id并显示所选值!!!

答案 1 :(得分:1)

如果您使用的是SimpleForm,那么:

= f.input :age_to, .., :input_html => { :id => 'myid' }

答案 2 :(得分:1)

尝试:

= f.input :age_to, :label => "Age from", :collection => 18..60, :value_method => 19, :input_html => { :id => 'myid' }